Skip to content

Commit 2802828

Browse files
refactor(lint): fixing using lint
1 parent 514ed6d commit 2802828

13 files changed

Lines changed: 76 additions & 25 deletions

File tree

cmd/cli/cmd/deploy.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66
import (
77
"faas-engine-go/internal/buildcontext"
88
"fmt"
9+
"log"
910
"log/slog"
1011
"path/filepath"
1112

@@ -50,6 +51,10 @@ func init() {
5051
deployCmd.Flags().StringVar(&filePath, "file", "", "Path to the function code directory")
5152
deployCmd.Flags().StringVar(&functionName, "function-name", "", "Name of the function to deploy")
5253

53-
deployCmd.MarkFlagRequired("file")
54-
deployCmd.MarkFlagRequired("function-name")
54+
if err := deployCmd.MarkFlagRequired("file"); err != nil {
55+
log.Fatalf("failed to mark flag as required: %v", err)
56+
}
57+
if err := deployCmd.MarkFlagRequired("function-name"); err != nil {
58+
log.Fatalf("failed to mark flag as required: %v", err)
59+
}
5560
}

cmd/cli/cmd/invoke.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66
import (
77
"fmt"
88
"io"
9+
"log"
910
"net/http"
1011
"strings"
1112
"time"
@@ -73,6 +74,11 @@ func init() {
7374
invokeCmd.Flags().StringVar(&functionName, "name", "", "Name of the function to invoke")
7475
invokeCmd.Flags().StringVar(&data, "data", "", "Data to pass to the function as input")
7576

76-
invokeCmd.MarkFlagRequired("name")
77-
invokeCmd.MarkFlagRequired("data")
77+
if err := invokeCmd.MarkFlagRequired("name"); err != nil {
78+
log.Fatalf("failed to mark 'name' flag as required: %v", err)
79+
}
80+
81+
if err := invokeCmd.MarkFlagRequired("data"); err != nil {
82+
log.Fatalf("failed to mark 'data' flag as required: %v", err)
83+
}
7884
}

cmd/cli/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Copyright © 2026 NAME HERE <EMAIL ADDRESS>
44
package cmd
55

66
import (
7+
"fmt"
78
"os"
89

910
"github.com/spf13/cobra"
@@ -31,6 +32,7 @@ var rootCmd = &cobra.Command{
3132
func Execute() {
3233
err := rootCmd.Execute()
3334
if err != nil {
35+
fmt.Fprintln(os.Stderr, err)
3436
os.Exit(1)
3537
}
3638
}

cmd/runtime-manager/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"faas-engine-go/internal/sdk"
77
"faas-engine-go/internal/service"
88
"fmt"
9+
"log"
910
"net/http"
1011

1112
"github.com/gorilla/mux"
@@ -32,9 +33,10 @@ func main() {
3233
r.HandleFunc("/functions", api.GetFunctionsHandler).Methods("GET")
3334
r.HandleFunc("/functions/{functionName}", api.DeleteFunctionHandler).Methods("DELETE")
3435

35-
http.ListenAndServe(":8080", r)
36+
if err = http.ListenAndServe(":8080", r); err != nil {
37+
log.Fatalf("server failed: %v", err)
38+
}
3639
}
37-
3840
func HomeHandler(w http.ResponseWriter, r *http.Request) {
3941
fmt.Fprintf(w, "Welcome to the Runtime Manager!")
4042
}

internal/api/delete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ func DeleteFunctionHandler(w http.ResponseWriter, r *http.Request) {
1616

1717
w.Header().Set("Content-type", "application/json")
1818
w.WriteHeader(http.StatusOK)
19-
json.NewEncoder(w).Encode(response)
19+
if err := json.NewEncoder(w).Encode(response); err != nil {
20+
http.Error(w, err.Error(), http.StatusInternalServerError)
21+
}
2022
}

internal/api/deploy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ func DeployHandler(deployer Deployer) http.HandlerFunc {
6060
func writeJSON(w http.ResponseWriter, status int, payload any) {
6161
w.Header().Set("Content-Type", "application/json")
6262
w.WriteHeader(status)
63-
json.NewEncoder(w).Encode(payload)
63+
if err := json.NewEncoder(w).Encode(payload); err != nil {
64+
http.Error(w, err.Error(), http.StatusInternalServerError)
65+
}
6466
}

internal/api/get.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ func GetFunctionsHandler(w http.ResponseWriter, r *http.Request) {
1616

1717
w.Header().Set("Content-type", "application/json")
1818
w.WriteHeader(http.StatusOK)
19-
json.NewEncoder(w).Encode(response)
19+
if err := json.NewEncoder(w).Encode(response); err != nil {
20+
http.Error(w, err.Error(), http.StatusInternalServerError)
21+
}
2022
}

internal/api/health.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ func GreetHandler(w http.ResponseWriter, r *http.Request) {
2121
if name == "" {
2222

2323
w.WriteHeader(http.StatusBadRequest)
24-
json.NewEncoder(w).Encode(response{
24+
if err := json.NewEncoder(w).Encode(response{
2525
Message: "Missing 'name' query parameter",
26-
})
26+
}); err != nil {
27+
http.Error(w, err.Error(), http.StatusInternalServerError)
28+
}
2729
return
2830
}
2931

3032
w.WriteHeader(http.StatusOK)
31-
json.NewEncoder(w).Encode(response{
33+
if err := json.NewEncoder(w).Encode(response{
3234
Message: fmt.Sprintf("Hello, %s!", name),
33-
})
35+
}); err != nil {
36+
http.Error(w, err.Error(), http.StatusInternalServerError)
37+
}
3438
}

internal/api/invoke.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func InvokeHandler(invoker Invoker) http.HandlerFunc {
3838

3939
w.Header().Set("Content-Type", "application/json")
4040
w.WriteHeader(http.StatusOK)
41-
json.NewEncoder(w).Encode(result)
41+
if err := json.NewEncoder(w).Encode(result); err != nil {
42+
http.Error(w, err.Error(), http.StatusInternalServerError)
43+
}
4244
}
4345
}

internal/sdk/image.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func PullImage(ctx context.Context, apiclient *client.Client, imageName string)
1919

2020
defer imageRef.Close()
2121
slog.Info("Pulling image....")
22-
io.Copy(io.Discard, imageRef)
22+
if _, err := io.Copy(io.Discard, imageRef); err != nil {
23+
return fmt.Errorf("failed to copy image data: %w", err)
24+
}
2325
return nil
2426
}
2527

@@ -110,7 +112,9 @@ func PushImage(ctx context.Context, apiclient *client.Client, target string) err
110112
return fmt.Errorf("failed to push image: %w", err)
111113
}
112114
defer imagePush.Close()
113-
io.Copy(io.Discard, imagePush)
115+
if _, err := io.Copy(io.Discard, imagePush); err != nil {
116+
return fmt.Errorf("failed to read push output: %w", err)
117+
}
114118
return nil
115119
}
116120

0 commit comments

Comments
 (0)