Skip to content

Commit

Permalink
perf
Browse files Browse the repository at this point in the history
  • Loading branch information
onewesong committed Jul 27, 2023
1 parent 88ad89c commit 5f20e6f
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 100 deletions.
4 changes: 2 additions & 2 deletions cmd/goforward/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var rootCmd = &cobra.Command{
if err != nil {
return err
}
err = runServer(*cfg)
err = runServer(cfg)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -79,7 +79,7 @@ func Execute() {
}
}

func runServer(cfg config.Config) (err error) {
func runServer(cfg *config.Config) (err error) {
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor)

if cfgFile != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/forward/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type AddForwardRequest struct {
func Add(c *gin.Context) {
var request AddForwardRequest
c.ShouldBindJSON(&request)
if len(request.ForwardLink) == 0 {
if request.ForwardLink == "" {
c.JSON(400, gin.H{"error": "forward link is empty"})
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/api/forward/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Del(c *gin.Context) {
m := manager.GetInstance()
listenAddr := c.Param("listen_addr")
if len(listenAddr) == 0 {
if listenAddr == "" {
c.JSON(400, gin.H{"error": "listen_addr is empty"})
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/constants/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package constants

const VERSION = "0.1.0"
const VERSION = "0.1.1"
10 changes: 5 additions & 5 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ type Manager struct {
ForwardMap map[string]*forward.Forward
}

func (m Manager) AddForward(ForwardLinks models.ForwardLinks, override bool) error {
for _, i := range ForwardLinks {
func (m Manager) AddForward(forwardLinks models.ForwardLinks, override bool) error {
for _, i := range forwardLinks {
key := i.ListenAddr.String()
forward := forward.NewForward(i)
forwardIns := forward.NewForward(i)
if f, ok := m.ForwardMap[key]; ok {
if override {
err := f.Stop()
Expand All @@ -25,11 +25,11 @@ func (m Manager) AddForward(ForwardLinks models.ForwardLinks, override bool) err
return fmt.Errorf("forward %s already exists, if want to override, set param override to true", key)
}
}
err := forward.Start()
err := forwardIns.Start()
if err != nil {
return fmt.Errorf("forward %s start err: %s", key, err)
}
m.ForwardMap[key] = forward
m.ForwardMap[key] = forwardIns
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/forward/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func (f *Forward) MarshalJSON() ([]byte, error) {
})
}

func NewForward(ForwardLink models.ForwardLink) *Forward {
func NewForward(forwardLink models.ForwardLink) *Forward {
return &Forward{
Link: ForwardLink,
Link: forwardLink,
quit: make(chan bool, 1),
}
}
6 changes: 3 additions & 3 deletions internal/pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ func init() {
Log.SetLogFuncCallDepth(Log.GetLogFuncCallDepth() + 1)
}

func InitLog(logWay string, logFile string, logLevel string, maxdays int64, disableLogColor bool) {
func InitLog(logWay, logFile, logLevel string, maxdays int64, disableLogColor bool) {
SetLogFile(logWay, logFile, maxdays, disableLogColor)
SetLogLevel(logLevel)
}

// SetLogFile to configure log params
// logWay: file or console
func SetLogFile(logWay string, logFile string, maxdays int64, disableLogColor bool) {
func SetLogFile(logWay, logFile string, maxdays int64, disableLogColor bool) {
if logWay == "console" {
params := ""
if disableLogColor {
params = fmt.Sprintf(`{"color": false}`)
}
Log.SetLogger("console", params)
} else {
params := fmt.Sprintf(`{"filename": "%s", "maxdays": %d}`, logFile, maxdays)
params := fmt.Sprintf(`{"filename": "%q", "maxdays": %d}`, logFile, maxdays)
Log.SetLogger("file", params)
}
}
Expand Down
52 changes: 0 additions & 52 deletions internal/util/util.go

This file was deleted.

33 changes: 0 additions & 33 deletions internal/util/util_test.go

This file was deleted.

0 comments on commit 5f20e6f

Please sign in to comment.