Improve CLI features and add new root command
- Implement new root command who return local version and remote backend version - Refactor and move some ping request logic into handler - Use Ping.Version to new function to get backend version - Add some color to the CLI output - Fix some version check logic
- commit
- f8e44ec51ce40920a5b819cad839d83418057583
- author
- bnema · · 2023-11-07 10:51 UTC
- parent
- 24fc1cd
- signature
- unsigned
6 files · +103 -61
M cmd/cli/main.go +1 -0
| @@ -21,6 +21,7 @@ var ( | |||
| 21 | 21 | var rootCmd = &cobra.Command{Use: "gordon"} | |
| 22 | 22 | ||
| 23 | 23 | func InitializeCommands(client *cli.App, server *server.App) { | |
| 24 | + | rootCmd.AddCommand(cmd.NewRootCommand(client)) | |
| 24 | 25 | rootCmd.AddCommand(cmd.NewServeCommand(server)) | |
| 25 | 26 | rootCmd.AddCommand(cmd.NewPingCommand(client)) | |
| 26 | 27 | rootCmd.AddCommand(cmd.NewDeployCommand(client)) | |
| @@ -21,6 +21,7 @@ var ( | |||||
| 21 | var rootCmd = &cobra.Command{Use: "gordon"} | 21 | var rootCmd = &cobra.Command{Use: "gordon"} | ||
| 22 | 22 | ||||
| 23 | func InitializeCommands(client *cli.App, server *server.App) { | 23 | func InitializeCommands(client *cli.App, server *server.App) { | ||
| 24 | + | rootCmd.AddCommand(cmd.NewRootCommand(client)) | |||
| 24 | rootCmd.AddCommand(cmd.NewServeCommand(server)) | 25 | rootCmd.AddCommand(cmd.NewServeCommand(server)) | ||
| 25 | rootCmd.AddCommand(cmd.NewPingCommand(client)) | 26 | rootCmd.AddCommand(cmd.NewPingCommand(client)) | ||
| 26 | rootCmd.AddCommand(cmd.NewDeployCommand(client)) | 27 | rootCmd.AddCommand(cmd.NewDeployCommand(client)) | ||
M internal/cli/cmd/ping.go +3 -51
| @@ -1,26 +1,17 @@ | |||
| 1 | 1 | package cmd | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "encoding/json" | |
| 5 | 4 | "fmt" | |
| 6 | - | "net/http" | |
| 7 | 5 | "os" | |
| 8 | 6 | "time" | |
| 9 | 7 | ||
| 10 | 8 | "github.com/bnema/gordon/internal/cli" | |
| 11 | 9 | "github.com/bnema/gordon/internal/cli/handler" | |
| 12 | - | "github.com/bnema/gordon/internal/common" | |
| 13 | 10 | "github.com/bnema/gordon/pkg/humanize" | |
| 14 | 11 | ||
| 15 | 12 | "github.com/spf13/cobra" | |
| 16 | 13 | ) | |
| 17 | 14 | ||
| 18 | - | // Define a struct to match the JSON response structure | |
| 19 | - | type PingResponse struct { | |
| 20 | - | Uptime string `json:"uptime"` | |
| 21 | - | Version string `json:"version"` | |
| 22 | - | } | |
| 23 | - | ||
| 24 | 15 | func NewPingCommand(a *cli.App) *cobra.Command { | |
| 25 | 16 | // handler.FieldCheck(a) | |
| 26 | 17 | return &cobra.Command{ | |
| @@ -33,47 +24,9 @@ func NewPingCommand(a *cli.App) *cobra.Command { | |||
| 33 | 24 | } | |
| 34 | 25 | }, | |
| 35 | 26 | Run: func(cmd *cobra.Command, args []string) { | |
| 36 | - | data := map[string]interface{}{"message": "ping"} | |
| 37 | - | payload, err := common.NewPingPayload(data) | |
| 38 | - | if err != nil { | |
| 39 | - | fmt.Println("Error creating payload:", err) | |
| 40 | - | return | |
| 41 | - | } | |
| 42 | - | ||
| 43 | - | // Create a RequestPayload and populate it | |
| 44 | - | reqPayload := common.RequestPayload{ | |
| 45 | - | Type: "ping", | |
| 46 | - | Payload: payload, | |
| 47 | - | } | |
| 48 | - | ||
| 49 | - | resp, err := handler.SendHTTPRequest(a, &reqPayload, "GET", "/ping") | |
| 50 | - | if err != nil { | |
| 51 | - | fmt.Println("Error sending HTTP request:", err) | |
| 52 | - | return | |
| 53 | - | } | |
| 54 | - | ||
| 55 | - | // Check for non-200 status codes | |
| 56 | - | if resp.StatusCode != http.StatusOK { | |
| 57 | - | fmt.Printf("Received non-OK response from server: %s\n", resp.StatusCode) | |
| 58 | - | return | |
| 59 | - | } | |
| 60 | - | ||
| 61 | - | // Check for the correct Content-Type header | |
| 62 | - | if contentType := resp.Header.Get("Content-Type"); contentType != "application/json" { | |
| 63 | - | fmt.Printf("Expected application/json response, got %s\n", contentType) | |
| 64 | - | return | |
| 65 | - | } | |
| 66 | - | ||
| 67 | - | if resp.StatusCode == 401 || resp.StatusCode == 403 || resp.StatusCode == 404 { | |
| 68 | - | fmt.Println("Login incorrect, edit your config file and try again") | |
| 69 | - | return | |
| 70 | - | } | |
| 71 | - | ||
| 72 | - | // Unmarshal the JSON response into the PingResponse struct | |
| 73 | - | var pingResp PingResponse | |
| 74 | - | err = json.Unmarshal(resp.Body, &pingResp) | |
| 27 | + | pingResp, err := handler.PerformPingRequest(a) | |
| 75 | 28 | if err != nil { | |
| 76 | - | fmt.Println("Error unmarshalling response:", err) | |
| 29 | + | fmt.Println("Error:", err) | |
| 77 | 30 | return | |
| 78 | 31 | } | |
| 79 | 32 | ||
| @@ -90,9 +43,8 @@ func NewPingCommand(a *cli.App) *cobra.Command { | |||
| 90 | 43 | // Use humanize to get a human-readable representation of the start time | |
| 91 | 44 | humanizedUptime := humanize.TimeAgo(startTime) | |
| 92 | 45 | ||
| 93 | - | /// Print the information | |
| 46 | + | // Print the information | |
| 94 | 47 | fmt.Printf("Pong!\nServer up since: %s\nServer version: %s\n", humanizedUptime, pingResp.Version) | |
| 95 | - | ||
| 96 | 48 | }, | |
| 97 | 49 | } | |
| 98 | 50 | } | |
| @@ -1,26 +1,17 @@ | |||||
| 1 | package cmd | 1 | package cmd | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | - | "encoding/json" | |||
| 5 | "fmt" | 4 | "fmt" | ||
| 6 | - | "net/http" | |||
| 7 | "os" | 5 | "os" | ||
| 8 | "time" | 6 | "time" | ||
| 9 | 7 | ||||
| 10 | "github.com/bnema/gordon/internal/cli" | 8 | "github.com/bnema/gordon/internal/cli" | ||
| 11 | "github.com/bnema/gordon/internal/cli/handler" | 9 | "github.com/bnema/gordon/internal/cli/handler" | ||
| 12 | - | "github.com/bnema/gordon/internal/common" | |||
| 13 | "github.com/bnema/gordon/pkg/humanize" | 10 | "github.com/bnema/gordon/pkg/humanize" | ||
| 14 | 11 | ||||
| 15 | "github.com/spf13/cobra" | 12 | "github.com/spf13/cobra" | ||
| 16 | ) | 13 | ) | ||
| 17 | 14 | ||||
| 18 | - | // Define a struct to match the JSON response structure | |||
| 19 | - | type PingResponse struct { | |||
| 20 | - | Uptime string `json:"uptime"` | |||
| 21 | - | Version string `json:"version"` | |||
| 22 | - | } | |||
| 23 | - | ||||
| 24 | func NewPingCommand(a *cli.App) *cobra.Command { | 15 | func NewPingCommand(a *cli.App) *cobra.Command { | ||
| 25 | // handler.FieldCheck(a) | 16 | // handler.FieldCheck(a) | ||
| 26 | return &cobra.Command{ | 17 | return &cobra.Command{ | ||
| @@ -33,47 +24,9 @@ func NewPingCommand(a *cli.App) *cobra.Command { | |||||
| 33 | } | 24 | } | ||
| 34 | }, | 25 | }, | ||
| 35 | Run: func(cmd *cobra.Command, args []string) { | 26 | Run: func(cmd *cobra.Command, args []string) { | ||
| 36 | - | data := map[string]interface{}{"message": "ping"} | 27 | + | pingResp, err := handler.PerformPingRequest(a) |
| 37 | - | payload, err := common.NewPingPayload(data) | |||
| 38 | - | if err != nil { | |||
| 39 | - | fmt.Println("Error creating payload:", err) | |||
| 40 | - | return | |||
| 41 | - | } | |||
| 42 | - | ||||
| 43 | - | // Create a RequestPayload and populate it | |||
| 44 | - | reqPayload := common.RequestPayload{ | |||
| 45 | - | Type: "ping", | |||
| 46 | - | Payload: payload, | |||
| 47 | - | } | |||
| 48 | - | ||||
| 49 | - | resp, err := handler.SendHTTPRequest(a, &reqPayload, "GET", "/ping") | |||
| 50 | - | if err != nil { | |||
| 51 | - | fmt.Println("Error sending HTTP request:", err) | |||
| 52 | - | return | |||
| 53 | - | } | |||
| 54 | - | ||||
| 55 | - | // Check for non-200 status codes | |||
| 56 | - | if resp.StatusCode != http.StatusOK { | |||
| 57 | - | fmt.Printf("Received non-OK response from server: %s\n", resp.StatusCode) | |||
| 58 | - | return | |||
| 59 | - | } | |||
| 60 | - | ||||
| 61 | - | // Check for the correct Content-Type header | |||
| 62 | - | if contentType := resp.Header.Get("Content-Type"); contentType != "application/json" { | |||
| 63 | - | fmt.Printf("Expected application/json response, got %s\n", contentType) | |||
| 64 | - | return | |||
| 65 | - | } | |||
| 66 | - | ||||
| 67 | - | if resp.StatusCode == 401 || resp.StatusCode == 403 || resp.StatusCode == 404 { | |||
| 68 | - | fmt.Println("Login incorrect, edit your config file and try again") | |||
| 69 | - | return | |||
| 70 | - | } | |||
| 71 | - | ||||
| 72 | - | // Unmarshal the JSON response into the PingResponse struct | |||
| 73 | - | var pingResp PingResponse | |||
| 74 | - | err = json.Unmarshal(resp.Body, &pingResp) | |||
| 75 | if err != nil { | 28 | if err != nil { | ||
| 76 | - | fmt.Println("Error unmarshalling response:", err) | 29 | + | fmt.Println("Error:", err) |
| 77 | return | 30 | return | ||
| 78 | } | 31 | } | ||
| 79 | 32 | ||||
| @@ -90,9 +43,8 @@ func NewPingCommand(a *cli.App) *cobra.Command { | |||||
| 90 | // Use humanize to get a human-readable representation of the start time | 43 | // Use humanize to get a human-readable representation of the start time | ||
| 91 | humanizedUptime := humanize.TimeAgo(startTime) | 44 | humanizedUptime := humanize.TimeAgo(startTime) | ||
| 92 | 45 | ||||
| 93 | - | /// Print the information | 46 | + | // Print the information |
| 94 | fmt.Printf("Pong!\nServer up since: %s\nServer version: %s\n", humanizedUptime, pingResp.Version) | 47 | fmt.Printf("Pong!\nServer up since: %s\nServer version: %s\n", humanizedUptime, pingResp.Version) | ||
| 95 | - | ||||
| 96 | }, | 48 | }, | ||
| 97 | } | 49 | } | ||
| 98 | } | 50 | } | ||
M internal/cli/cmd/root.go +37 -5
| @@ -1,8 +1,40 @@ | |||
| 1 | 1 | // the root command is the entrypoint for the gordon cli (default: client) | |
| 2 | 2 | package cmd | |
| 3 | 3 | ||
| 4 | - | // if no command selected print all commands | |
| 5 | - | // available commands for now are: | |
| 6 | - | // - deploy | |
| 7 | - | // - serve | |
| 8 | - | // - version | |
| 4 | + | import ( | |
| 5 | + | "fmt" | |
| 6 | + | ||
| 7 | + | "github.com/bnema/gordon/internal/cli" | |
| 8 | + | "github.com/bnema/gordon/internal/cli/handler" | |
| 9 | + | "github.com/fatih/color" | |
| 10 | + | "github.com/spf13/cobra" | |
| 11 | + | ) | |
| 12 | + | ||
| 13 | + | // NewRootCommand creates a new root command | |
| 14 | + | func NewRootCommand(a *cli.App) *cobra.Command { | |
| 15 | + | cmd := &cobra.Command{ | |
| 16 | + | Use: "gordon", | |
| 17 | + | Short: "Gordon is a CLI for the Gordon project", | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | backendVersion, err := getBackendVersion(a) | |
| 21 | + | if err != nil { | |
| 22 | + | fmt.Println("Error getting backend version:", err) | |
| 23 | + | return cmd | |
| 24 | + | } | |
| 25 | + | ||
| 26 | + | // Using color.Green function to print in green | |
| 27 | + | color.Green("Gordon %s", a.Config.GetVersion()) | |
| 28 | + | color.Blue("Gordon Backend %s", backendVersion) | |
| 29 | + | ||
| 30 | + | return cmd | |
| 31 | + | } | |
| 32 | + | ||
| 33 | + | func getBackendVersion(a *cli.App) (string, error) { | |
| 34 | + | pingResp, err := handler.PerformPingRequest(a) | |
| 35 | + | if err != nil { | |
| 36 | + | return "", err | |
| 37 | + | } | |
| 38 | + | ||
| 39 | + | return pingResp.Version, nil | |
| 40 | + | } | |
| @@ -1,8 +1,40 @@ | |||||
| 1 | // the root command is the entrypoint for the gordon cli (default: client) | 1 | // the root command is the entrypoint for the gordon cli (default: client) | ||
| 2 | package cmd | 2 | package cmd | ||
| 3 | 3 | ||||
| 4 | - | // if no command selected print all commands | 4 | + | import ( |
| 5 | - | // available commands for now are: | 5 | + | "fmt" |
| 6 | - | // - deploy | 6 | + | |
| 7 | - | // - serve | 7 | + | "github.com/bnema/gordon/internal/cli" |
| 8 | - | // - version | 8 | + | "github.com/bnema/gordon/internal/cli/handler" |
| 9 | + | "github.com/fatih/color" | |||
| 10 | + | "github.com/spf13/cobra" | |||
| 11 | + | ) | |||
| 12 | + | ||||
| 13 | + | // NewRootCommand creates a new root command | |||
| 14 | + | func NewRootCommand(a *cli.App) *cobra.Command { | |||
| 15 | + | cmd := &cobra.Command{ | |||
| 16 | + | Use: "gordon", | |||
| 17 | + | Short: "Gordon is a CLI for the Gordon project", | |||
| 18 | + | } | |||
| 19 | + | ||||
| 20 | + | backendVersion, err := getBackendVersion(a) | |||
| 21 | + | if err != nil { | |||
| 22 | + | fmt.Println("Error getting backend version:", err) | |||
| 23 | + | return cmd | |||
| 24 | + | } | |||
| 25 | + | ||||
| 26 | + | // Using color.Green function to print in green | |||
| 27 | + | color.Green("Gordon %s", a.Config.GetVersion()) | |||
| 28 | + | color.Blue("Gordon Backend %s", backendVersion) | |||
| 29 | + | ||||
| 30 | + | return cmd | |||
| 31 | + | } | |||
| 32 | + | ||||
| 33 | + | func getBackendVersion(a *cli.App) (string, error) { | |||
| 34 | + | pingResp, err := handler.PerformPingRequest(a) | |||
| 35 | + | if err != nil { | |||
| 36 | + | return "", err | |||
| 37 | + | } | |||
| 38 | + | ||||
| 39 | + | return pingResp.Version, nil | |||
| 40 | + | } | |||
A internal/cli/handler/pingrequest.go +54 -0
| @@ -0,0 +1,54 @@ | |||
| 1 | + | package handler | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "encoding/json" | |
| 5 | + | "fmt" | |
| 6 | + | "net/http" | |
| 7 | + | ||
| 8 | + | "github.com/bnema/gordon/internal/cli" | |
| 9 | + | "github.com/bnema/gordon/internal/common" | |
| 10 | + | ) | |
| 11 | + | ||
| 12 | + | // Define a struct to match the JSON response structure | |
| 13 | + | type PingResponse struct { | |
| 14 | + | Uptime string `json:"uptime"` | |
| 15 | + | Version string `json:"version"` | |
| 16 | + | } | |
| 17 | + | ||
| 18 | + | func PerformPingRequest(a *cli.App) (PingResponse, error) { | |
| 19 | + | var pingResp PingResponse | |
| 20 | + | ||
| 21 | + | data := map[string]interface{}{"message": "ping"} | |
| 22 | + | payload, err := common.NewPingPayload(data) | |
| 23 | + | if err != nil { | |
| 24 | + | return pingResp, fmt.Errorf("failed to create new ping payload: %w", err) | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | // Create a RequestPayload and populate it | |
| 28 | + | reqPayload := common.RequestPayload{ | |
| 29 | + | Type: "ping", | |
| 30 | + | Payload: payload, | |
| 31 | + | } | |
| 32 | + | ||
| 33 | + | resp, err := SendHTTPRequest(a, &reqPayload, "GET", "/ping") | |
| 34 | + | if err != nil { | |
| 35 | + | return pingResp, fmt.Errorf("failed to reach backend") | |
| 36 | + | } | |
| 37 | + | ||
| 38 | + | defer resp.Http.Body.Close() | |
| 39 | + | ||
| 40 | + | if resp.StatusCode != http.StatusOK { | |
| 41 | + | return PingResponse{ | |
| 42 | + | Uptime: "", | |
| 43 | + | Version: "", | |
| 44 | + | }, fmt.Errorf("expected status code 200, got %d", resp.StatusCode) | |
| 45 | + | } | |
| 46 | + | ||
| 47 | + | // Unmarshal the JSON response into the PingResponse struct | |
| 48 | + | err = json.Unmarshal(resp.Body, &pingResp) | |
| 49 | + | if err != nil { | |
| 50 | + | return pingResp, err | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | return pingResp, nil | |
| 54 | + | } | |
| @@ -0,0 +1,54 @@ | |||||
| 1 | + | package handler | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "encoding/json" | |||
| 5 | + | "fmt" | |||
| 6 | + | "net/http" | |||
| 7 | + | ||||
| 8 | + | "github.com/bnema/gordon/internal/cli" | |||
| 9 | + | "github.com/bnema/gordon/internal/common" | |||
| 10 | + | ) | |||
| 11 | + | ||||
| 12 | + | // Define a struct to match the JSON response structure | |||
| 13 | + | type PingResponse struct { | |||
| 14 | + | Uptime string `json:"uptime"` | |||
| 15 | + | Version string `json:"version"` | |||
| 16 | + | } | |||
| 17 | + | ||||
| 18 | + | func PerformPingRequest(a *cli.App) (PingResponse, error) { | |||
| 19 | + | var pingResp PingResponse | |||
| 20 | + | ||||
| 21 | + | data := map[string]interface{}{"message": "ping"} | |||
| 22 | + | payload, err := common.NewPingPayload(data) | |||
| 23 | + | if err != nil { | |||
| 24 | + | return pingResp, fmt.Errorf("failed to create new ping payload: %w", err) | |||
| 25 | + | } | |||
| 26 | + | ||||
| 27 | + | // Create a RequestPayload and populate it | |||
| 28 | + | reqPayload := common.RequestPayload{ | |||
| 29 | + | Type: "ping", | |||
| 30 | + | Payload: payload, | |||
| 31 | + | } | |||
| 32 | + | ||||
| 33 | + | resp, err := SendHTTPRequest(a, &reqPayload, "GET", "/ping") | |||
| 34 | + | if err != nil { | |||
| 35 | + | return pingResp, fmt.Errorf("failed to reach backend") | |||
| 36 | + | } | |||
| 37 | + | ||||
| 38 | + | defer resp.Http.Body.Close() | |||
| 39 | + | ||||
| 40 | + | if resp.StatusCode != http.StatusOK { | |||
| 41 | + | return PingResponse{ | |||
| 42 | + | Uptime: "", | |||
| 43 | + | Version: "", | |||
| 44 | + | }, fmt.Errorf("expected status code 200, got %d", resp.StatusCode) | |||
| 45 | + | } | |||
| 46 | + | ||||
| 47 | + | // Unmarshal the JSON response into the PingResponse struct | |||
| 48 | + | err = json.Unmarshal(resp.Body, &pingResp) | |||
| 49 | + | if err != nil { | |||
| 50 | + | return pingResp, err | |||
| 51 | + | } | |||
| 52 | + | ||||
| 53 | + | return pingResp, nil | |||
| 54 | + | } | |||
M internal/common/version.go +8 -3
| @@ -10,6 +10,7 @@ import ( | |||
| 10 | 10 | "time" | |
| 11 | 11 | ||
| 12 | 12 | "github.com/bnema/gordon/pkg/docker" | |
| 13 | + | "github.com/fatih/color" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| 15 | 16 | type CurrentVersion struct { | |
| @@ -66,14 +67,18 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||
| 66 | 67 | remoteVersion = remoteVersions.Name | |
| 67 | 68 | } | |
| 68 | 69 | ||
| 69 | - | fmt.Printf("Local version: %s\n", localVersion.Version) | |
| 70 | 70 | remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1] | |
| 71 | - | fmt.Printf("Remote version: %s\n", remoteVersion) | |
| 72 | 71 | message := CheckForNewVersion(localVersion.Version, remoteVersion) | |
| 72 | + | ||
| 73 | 73 | if message != "" { | |
| 74 | - | return fmt.Sprintf("New version %s is available", remoteVersion), nil | |
| 74 | + | // Create a new color attribute | |
| 75 | + | green := color.New(color.FgGreen).SprintFunc() | |
| 76 | + | // Use the color attribute to format the string with ANSI codes | |
| 77 | + | coloredMessage := green(fmt.Sprintf("New version %s is available", remoteVersion)) | |
| 78 | + | return coloredMessage, nil | |
| 75 | 79 | } | |
| 76 | 80 | return "", nil | |
| 81 | + | ||
| 77 | 82 | } | |
| 78 | 83 | ||
| 79 | 84 | func CheckVersionPeriodically(c *Config) (string, error) { | |
| @@ -10,6 +10,7 @@ import ( | |||||
| 10 | "time" | 10 | "time" | ||
| 11 | 11 | ||||
| 12 | "github.com/bnema/gordon/pkg/docker" | 12 | "github.com/bnema/gordon/pkg/docker" | ||
| 13 | + | "github.com/fatih/color" | |||
| 13 | ) | 14 | ) | ||
| 14 | 15 | ||||
| 15 | type CurrentVersion struct { | 16 | type CurrentVersion struct { | ||
| @@ -66,14 +67,18 @@ func checkAndUpdateVersion(c *Config) (string, error) { | |||||
| 66 | remoteVersion = remoteVersions.Name | 67 | remoteVersion = remoteVersions.Name | ||
| 67 | } | 68 | } | ||
| 68 | 69 | ||||
| 69 | - | fmt.Printf("Local version: %s\n", localVersion.Version) | |||
| 70 | remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1] | 70 | remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1] | ||
| 71 | - | fmt.Printf("Remote version: %s\n", remoteVersion) | |||
| 72 | message := CheckForNewVersion(localVersion.Version, remoteVersion) | 71 | message := CheckForNewVersion(localVersion.Version, remoteVersion) | ||
| 72 | + | ||||
| 73 | if message != "" { | 73 | if message != "" { | ||
| 74 | - | return fmt.Sprintf("New version %s is available", remoteVersion), nil | 74 | + | // Create a new color attribute |
| 75 | + | green := color.New(color.FgGreen).SprintFunc() | |||
| 76 | + | // Use the color attribute to format the string with ANSI codes | |||
| 77 | + | coloredMessage := green(fmt.Sprintf("New version %s is available", remoteVersion)) | |||
| 78 | + | return coloredMessage, nil | |||
| 75 | } | 79 | } | ||
| 76 | return "", nil | 80 | return "", nil | ||
| 81 | + | ||||
| 77 | } | 82 | } | ||
| 78 | 83 | ||||
| 79 | func CheckVersionPeriodically(c *Config) (string, error) { | 84 | func CheckVersionPeriodically(c *Config) (string, error) { | ||
M internal/httpserve/middleware/secure.go +0 -2
| @@ -1,7 +1,6 @@ | |||
| 1 | 1 | package middleware | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "fmt" | |
| 5 | 4 | "log" | |
| 6 | 5 | "os" | |
| 7 | 6 | ||
| @@ -16,7 +15,6 @@ import ( | |||
| 16 | 15 | func SecureRoutes(a *server.App) echo.MiddlewareFunc { | |
| 17 | 16 | proxyURL := a.Config.Build.ProxyURL // <-- https://gordon-proxy.bnema.dev | |
| 18 | 17 | urlCheckVersion := a.Config.Build.ProxyURL + "/version" | |
| 19 | - | fmt.Println("Proxy URL:", proxyURL) | |
| 20 | 18 | return middleware.SecureWithConfig(middleware.SecureConfig{ | |
| 21 | 19 | XSSProtection: "1; mode=block", | |
| 22 | 20 | ContentTypeNosniff: "nosniff", | |
| @@ -1,7 +1,6 @@ | |||||
| 1 | package middleware | 1 | package middleware | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | - | "fmt" | |||
| 5 | "log" | 4 | "log" | ||
| 6 | "os" | 5 | "os" | ||
| 7 | 6 | ||||
| @@ -16,7 +15,6 @@ import ( | |||||
| 16 | func SecureRoutes(a *server.App) echo.MiddlewareFunc { | 15 | func SecureRoutes(a *server.App) echo.MiddlewareFunc { | ||
| 17 | proxyURL := a.Config.Build.ProxyURL // <-- https://gordon-proxy.bnema.dev | 16 | proxyURL := a.Config.Build.ProxyURL // <-- https://gordon-proxy.bnema.dev | ||
| 18 | urlCheckVersion := a.Config.Build.ProxyURL + "/version" | 17 | urlCheckVersion := a.Config.Build.ProxyURL + "/version" | ||
| 19 | - | fmt.Println("Proxy URL:", proxyURL) | |||
| 20 | return middleware.SecureWithConfig(middleware.SecureConfig{ | 18 | return middleware.SecureWithConfig(middleware.SecureConfig{ | ||
| 21 | XSSProtection: "1; mode=block", | 19 | XSSProtection: "1; mode=block", | ||
| 22 | ContentTypeNosniff: "nosniff", | 20 | ContentTypeNosniff: "nosniff", | ||