Skip to content

Commit

Permalink
style: automatically format the code, and repair and optimize the cod…
Browse files Browse the repository at this point in the history
…e related items according to the automatic analysis code report
  • Loading branch information
ClessLi committed Apr 7, 2022
1 parent e0aa6d6 commit 133e905
Show file tree
Hide file tree
Showing 186 changed files with 1,364 additions and 721 deletions.
6 changes: 3 additions & 3 deletions cmd/bifrost-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ package main
import (
"errors"
"fmt"
"github.com/ClessLi/bifrost/internal/pkg/auth/daemon"
"os"

"github.com/ClessLi/bifrost/internal/pkg/auth/daemon"
)

func main() {

defer daemon.Logf.Close()
defer daemon.Stdoutf.Close()

err := errors.New("unkown signal")
err := errors.New("unknown signal")
switch *daemon.Signal {
case "":
err = daemon.Start()
Expand Down
6 changes: 4 additions & 2 deletions cmd/bifrost/bifrost.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"github.com/ClessLi/bifrost/internal/bifrost"
"github.com/marmotedu/component-base/pkg/time"
"math/rand"
"os"
"runtime"

"github.com/marmotedu/component-base/pkg/time"

"github.com/ClessLi/bifrost/internal/bifrost"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ng_conf_format/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package main

import (
"fmt"
"github.com/ClessLi/bifrost/pkg/resolv/nginx"
"os"
"path/filepath"

"github.com/ClessLi/bifrost/pkg/resolv/nginx"
)

func init() {
if len(os.Args) < 2 {
usage()
os.Exit(1)
}

}

func usage() {
Expand Down
2 changes: 1 addition & 1 deletion internal/bifrost/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func run(opts *options.Options) app.RunFunc {
defer log.Flush()

// init auth api client
//auth.Init(opts.AuthAPIClient)
// auth.Init(opts.AuthAPIClient)

cfg, err := config.CreateConfigFromOptions(opts)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/bifrost/endpoint/v1/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewEndpoints(svc svcv1.ServiceFactory) EndpointsFactory {
func (e *endpoints) WebServerConfig() WebServerConfigEndpoints {
return web_server_config.NewWebServerConfigEndpoints(e.svc)
}

func (e *endpoints) WebServerStatistics() WebServerStatisticsEndpoints {
return web_server_statistics.NewWebServerStatisticsEndpoints(e.svc)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/bifrost/endpoint/v1/web_server_config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package web_server_config

import (
"context"
"github.com/ClessLi/bifrost/api/bifrost/v1"
pbv1 "github.com/ClessLi/bifrost/api/protobuf-spec/bifrostpb/v1"

"github.com/go-kit/kit/endpoint"
"github.com/marmotedu/errors"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
pbv1 "github.com/ClessLi/bifrost/api/protobuf-spec/bifrostpb/v1"
)

func (w *webServerConfigEndpoints) EndpointGetServerNames() endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
if _, ok := request.(*pbv1.Null); ok {
return w.svc.WebServerConfig().GetServerNames(ctx)
}

return nil, errors.Errorf("invalid get request, need *pbv1.Null, not %T", request)
}
}
Expand All @@ -22,6 +25,7 @@ func (w *webServerConfigEndpoints) EndpointGet() endpoint.Endpoint {
if req, ok := request.(*v1.ServerName); ok {
return w.svc.WebServerConfig().Get(ctx, req)
}

return nil, errors.Errorf("invalid get request, need *v1.ServerName, not %T", request)
}
}
6 changes: 5 additions & 1 deletion internal/bifrost/endpoint/v1/web_server_config/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package web_server_config

import (
"context"
v1 "github.com/ClessLi/bifrost/api/bifrost/v1"

"github.com/go-kit/kit/endpoint"
"github.com/marmotedu/errors"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
)

func (w *webServerConfigEndpoints) EndpointUpdate() endpoint.Endpoint {
Expand All @@ -14,8 +16,10 @@ func (w *webServerConfigEndpoints) EndpointUpdate() endpoint.Endpoint {
if err != nil {
return nil, err
}

return &v1.Response{Message: "update success"}, nil
}

return nil, errors.Errorf("invalid update request, need *v1.ServerConfig, not %T", request)
}
}
5 changes: 4 additions & 1 deletion internal/bifrost/endpoint/v1/web_server_log_watcher/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package web_server_log_watcher

import (
"context"
v1 "github.com/ClessLi/bifrost/api/bifrost/v1"

"github.com/go-kit/kit/endpoint"
"github.com/marmotedu/errors"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
)

func (w *webServerLogWatcherEndpoints) EndpointWatch() endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
if req, ok := request.(*v1.WebServerLogWatchRequest); ok {
return w.svc.WebServerLogWatcher().Watch(ctx, req)
}

return nil, errors.Errorf("invalid get request, need *v1.WebServerLogWatcherRequest, not %T", request)
}
}
5 changes: 4 additions & 1 deletion internal/bifrost/endpoint/v1/web_server_statistics/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package web_server_statistics

import (
"context"
v1 "github.com/ClessLi/bifrost/api/bifrost/v1"

"github.com/go-kit/kit/endpoint"
"github.com/marmotedu/errors"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
)

func (w *webServerStatisticsEndpoints) EndpointGet() endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
if req, ok := request.(*v1.ServerName); ok {
return w.svc.WebServerStatistics().Get(ctx, req)
}

return nil, errors.Errorf("invalid get request, need *v1.ServerName, not %T", request)
}
}
5 changes: 4 additions & 1 deletion internal/bifrost/endpoint/v1/web_server_status/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package web_server_status

import (
"context"
pbv1 "github.com/ClessLi/bifrost/api/protobuf-spec/bifrostpb/v1"

"github.com/go-kit/kit/endpoint"
"github.com/marmotedu/errors"

pbv1 "github.com/ClessLi/bifrost/api/protobuf-spec/bifrostpb/v1"
)

func (w *webServerStatusEndpoints) EndpointGet() endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
if _, ok := request.(*pbv1.Null); ok {
return w.svc.WebServerStatus().Get(ctx)
}

return nil, errors.Errorf("invalid get request, need *pbv1.Null, not %T", request)
}
}
5 changes: 3 additions & 2 deletions internal/bifrost/middleware/logging/log_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package logging

import (
"context"
"github.com/ClessLi/bifrost/internal/bifrost/middleware/utils"
"reflect"
"runtime"
"time"

"github.com/ClessLi/bifrost/internal/bifrost/middleware/utils"
)

type logFormatter struct {
Expand All @@ -23,7 +24,7 @@ func (l *logFormatter) Log(infos ...interface{}) {
if !reflect.DeepEqual(l.begin, time.Time{}) {
infos = append(infos, "took", time.Since(l.begin))
}
logger.Log(append(l.initInfos, infos...)...)
logger.Log(append(l.initInfos, infos...)...) //nolint:errcheck
}

func (l *logFormatter) SetResult(result interface{}) {
Expand Down
16 changes: 11 additions & 5 deletions internal/bifrost/middleware/logging/logging.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package logging

import (
"sync"

kitlog "github.com/go-kit/kit/log"

svcv1 "github.com/ClessLi/bifrost/internal/bifrost/service/v1"
log "github.com/ClessLi/bifrost/pkg/log/v1"
kitlog "github.com/go-kit/kit/log"
"sync"
)

var logger kitlog.Logger
var limit int
var once = sync.Once{}
var (
logger kitlog.Logger
limit int
once = sync.Once{}
)

type loggingService struct {
svc svcv1.ServiceFactory
Expand All @@ -36,6 +40,7 @@ func New(svc svcv1.ServiceFactory) svcv1.ServiceFactory {
logger = log.K()
limit = 100
})

return &loggingService{svc: svc}
}

Expand All @@ -46,5 +51,6 @@ func getLimitResult(result []byte) string {
} else {
formattedRet = result
}

return string(formattedRet) + "..."
}
13 changes: 10 additions & 3 deletions internal/bifrost/middleware/logging/web_server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package logging

import (
"context"
v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
svcv1 "github.com/ClessLi/bifrost/internal/bifrost/service/v1"
"strings"
"time"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
svcv1 "github.com/ClessLi/bifrost/internal/bifrost/service/v1"
)

type loggingWebServerConfigService struct {
Expand All @@ -26,10 +27,14 @@ func (l loggingWebServerConfigService) GetServerNames(ctx context.Context) (serv
}
logF.SetErr(err)
}(time.Now().Local())

return l.svc.GetServerNames(ctx)
}

func (l loggingWebServerConfigService) Get(ctx context.Context, servername *v1.ServerName) (wsc *v1.WebServerConfig, err error) {
func (l loggingWebServerConfigService) Get(
ctx context.Context,
servername *v1.ServerName,
) (wsc *v1.WebServerConfig, err error) {
defer func(begin time.Time) {
logF := newLogFormatter(ctx, l.svc.Get)
logF.SetBeginTime(begin)
Expand All @@ -42,6 +47,7 @@ func (l loggingWebServerConfigService) Get(ctx context.Context, servername *v1.S
}
logF.SetErr(err)
}(time.Now().Local())

return l.svc.Get(ctx, servername)
}

Expand All @@ -58,6 +64,7 @@ func (l loggingWebServerConfigService) Update(ctx context.Context, config *v1.We
}
logF.SetErr(err)
}(time.Now().Local())

return l.svc.Update(ctx, config)
}

Expand Down
9 changes: 7 additions & 2 deletions internal/bifrost/middleware/logging/web_server_log_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package logging

import (
"context"
"time"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
svcv1 "github.com/ClessLi/bifrost/internal/bifrost/service/v1"
"time"
)

type loggingWebServerLogWatcherService struct {
svc svcv1.WebServerLogWatcherService
}

func (l *loggingWebServerLogWatcherService) Watch(ctx context.Context, request *v1.WebServerLogWatchRequest) (wslog *v1.WebServerLog, err error) {
func (l *loggingWebServerLogWatcherService) Watch(
ctx context.Context,
request *v1.WebServerLogWatchRequest,
) (wslog *v1.WebServerLog, err error) {
defer func(begin time.Time) {
logF := newLogFormatter(ctx, l.svc.Watch)
logF.SetBeginTime(begin)
Expand All @@ -21,6 +25,7 @@ func (l *loggingWebServerLogWatcherService) Watch(ctx context.Context, request *
}
logF.SetErr(err)
}(time.Now().Local())

return l.svc.Watch(ctx, request)
}

Expand Down
10 changes: 7 additions & 3 deletions internal/bifrost/middleware/logging/web_server_statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ package logging
import (
"context"
"encoding/json"
"time"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
svcv1 "github.com/ClessLi/bifrost/internal/bifrost/service/v1"
"time"
)

type loggingWebServerStatisticsService struct {
svc svcv1.WebServerStatisticsService
}

func (l *loggingWebServerStatisticsService) Get(ctx context.Context, servername *v1.ServerName) (s *v1.Statistics, err error) {
func (l *loggingWebServerStatisticsService) Get(
ctx context.Context,
servername *v1.ServerName,
) (s *v1.Statistics, err error) {
defer func(begin time.Time) {
logF := newLogFormatter(ctx, l.svc.Get)
logF.SetBeginTime(begin)
Expand All @@ -24,8 +28,8 @@ func (l *loggingWebServerStatisticsService) Get(ctx context.Context, servername
result, _ := json.Marshal(s)
logF.SetResult(getLimitResult(result))
}

}(time.Now().Local())

return l.svc.Get(ctx, servername)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/bifrost/middleware/logging/web_server_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package logging
import (
"context"
"encoding/json"
"time"

v1 "github.com/ClessLi/bifrost/api/bifrost/v1"
svcv1 "github.com/ClessLi/bifrost/internal/bifrost/service/v1"
"time"
)

type loggingWebServerStatusService struct {
Expand All @@ -23,6 +24,7 @@ func (l *loggingWebServerStatusService) Get(ctx context.Context) (metrics *v1.Me
}
logF.SetErr(err)
}(time.Now().Local())

return l.svc.Get(ctx)
}

Expand Down
Loading

0 comments on commit 133e905

Please sign in to comment.