Skip to content

Commit a69df28

Browse files
authored
Merge pull request #183 from chaosi-zju/staticcheck2
chore: format code about exported function should have comment
2 parents 935fba4 + 8c357c5 commit a69df28

File tree

40 files changed

+67
-15
lines changed

40 files changed

+67
-15
lines changed

cmd/api/app/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Options struct {
3939
OpenAPIEnabled bool
4040
}
4141

42+
// NewOptions returns initialized Options.
4243
func NewOptions() *Options {
4344
return &Options{}
4445
}

cmd/api/app/types/api/v1/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1
1818

1919
import "github.com/karmada-io/dashboard/pkg/config"
2020

21+
// SetDashboardConfigRequest is the request for setting dashboard config
2122
type SetDashboardConfigRequest struct {
2223
DockerRegistries []config.DockerRegistry `json:"docker_registries"`
2324
ChartRegistries []config.ChartRegistry `json:"chart_registries"`

cmd/api/app/types/common/response.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/gin-gonic/gin"
2323
)
2424

25+
// BaseResponse is the base response
2526
type BaseResponse struct {
2627
Code int `json:"code"`
2728
Msg string `json:"message"`
@@ -38,6 +39,7 @@ func Fail(c *gin.Context, err error) {
3839
Response(c, err, nil)
3940
}
4041

42+
// Response generate response
4143
func Response(c *gin.Context, err error, data interface{}) {
4244
code := 200 // biz status code
4345
message := "success" // biz status message

cmd/metrics-scraper/app/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Options struct {
3939
OpenAPIEnabled bool
4040
}
4141

42+
// NewOptions returns initialized Options.
4243
func NewOptions() *Options {
4344
return &Options{}
4445
}

cmd/metrics-scraper/app/routes/metrics/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
var requests = make(chan scrape.SaveRequest)
2828

29+
// GetMetrics returns the metrics for the given app name
2930
func GetMetrics(c *gin.Context) {
3031
appName := c.Param("app_name")
3132
queryType := c.Query("type")

cmd/metrics-scraper/app/routes/metrics/handlerqueries.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ import (
2929
"github.com/karmada-io/dashboard/cmd/metrics-scraper/app/scrape"
3030
)
3131

32+
// MetricInfo represents the information about a metric.
3233
type MetricInfo struct {
3334
Help string `json:"help"`
3435
Type string `json:"type"`
3536
}
3637

38+
// QueryMetrics handles the querying of metrics.
3739
func QueryMetrics(c *gin.Context) {
3840
appName := c.Param("app_name")
3941
podName := c.Param("pod_name")

cmd/metrics-scraper/app/scrape/job.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ import (
3434
"github.com/karmada-io/dashboard/pkg/client"
3535
)
3636

37-
// Define a struct for save requests
37+
// SaveRequest Define a struct for save requests
3838
type SaveRequest struct {
3939
appName string
4040
podName string
4141
data *db.ParsedData
4242
result chan error
4343
}
4444

45+
// FetchMetrics fetches metrics from all pods of the given app name
4546
func FetchMetrics(ctx context.Context, appName string, requests chan SaveRequest) (map[string]*db.ParsedData, []string, error) {
4647
kubeClient := client.InClusterClient()
4748
podsMap, errors := getKarmadaPods(ctx, appName) // Pass context here

cmd/metrics-scraper/app/scrape/scrape.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func startAppMetricsFetcher(appName string) {
7979
}
8080
}
8181

82+
// CheckAppStatus checks the status of all registered apps and returns a map of app names to their status.
8283
func CheckAppStatus(c *gin.Context) {
8384
statusMap := make(map[string]bool)
8485

@@ -107,6 +108,8 @@ func CheckAppStatus(c *gin.Context) {
107108
c.JSON(http.StatusOK, statusMap)
108109
}
109110

111+
// HandleSyncOperation handles the sync operation for a specific app
112+
// if not specified, it handles the sync operation for all apps.
110113
func HandleSyncOperation(c *gin.Context, appName string, syncValue int, queryType string) {
111114
if appName == "" {
112115
// Stop all apps
@@ -188,6 +191,7 @@ func HandleSyncOperation(c *gin.Context, appName string, syncValue int, queryTyp
188191
}
189192
}
190193

194+
// InitDatabase initializes the database and starts the metrics fetchers.
191195
func InitDatabase() {
192196
// Initialize contexts and cancel functions
193197
appContexts = make(map[string]context.Context)

cmd/web/app/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Options struct {
3535
DashboardConfigPath string
3636
}
3737

38+
// NewOptions creates a new Options object with default parameters.
3839
func NewOptions() *Options {
3940
return &Options{}
4041
}

pkg/client/auth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func buildAuthInfo(request *http.Request) (*clientcmdapi.AuthInfo, error) {
8282
return authInfo, nil
8383
}
8484

85+
// HasAuthorizationHeader checks if the request has an authorization header.
8586
func HasAuthorizationHeader(req *http.Request) bool {
8687
header := req.Header.Get(authorizationHeader)
8788
if len(header) == 0 {
@@ -92,11 +93,13 @@ func HasAuthorizationHeader(req *http.Request) bool {
9293
return strings.HasPrefix(header, authorizationTokenPrefix) && len(token) > 0
9394
}
9495

96+
// GetBearerToken returns the bearer token from the authorization header.
9597
func GetBearerToken(req *http.Request) string {
9698
header := req.Header.Get(authorizationHeader)
9799
return extractBearerToken(header)
98100
}
99101

102+
// SetAuthorizationHeader sets the authorization header for the given request.
100103
func SetAuthorizationHeader(req *http.Request, token string) {
101104
req.Header.Set(authorizationHeader, authorizationTokenPrefix+token)
102105
}

0 commit comments

Comments
 (0)