Skip to content

Commit

Permalink
fix: many many golangci-lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
senselessDog committed Dec 19, 2024
1 parent da909d9 commit 332e789
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 1,173 deletions.
71 changes: 3 additions & 68 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,140 +20,75 @@ import (
var NF *service.NfApp

func main() {

defer func() {

if p := recover(); p != nil {

// Print stack for panic to log. Fatalf() will let program exit.

logger.MainLog.Fatalf("panic: %v\n%s", p, string(debug.Stack()))

}

}()

app := cli.NewApp()

app.Name = "anya"

app.Usage = "SPYxFamily"

app.Action = action

app.Flags = []cli.Flag{

cli.StringFlag{

Name: "config, c",

Name: "config, c",
Usage: "Load configuration from `FILE`",
},

cli.StringSliceFlag{

Name: "log, l",

Name: "log, l",
Usage: "Output NF log to `FILE`",
},
}

if err := app.Run(os.Args); err != nil {

logger.MainLog.Errorf("ANYA Run Error: %v\n", err)

}

}

func action(cliCtx *cli.Context) error {

tlsKeyLogPath, err := initLogFile(cliCtx.StringSlice("log"))

if err != nil {

return err

}

logger.MainLog.Infoln("Anya version: ", version.GetVersion())

cfg, err := factory.ReadConfig(cliCtx.String("config"))

if err != nil {

return err

}

factory.NfConfig = cfg

ctx, cancel := context.WithCancel(context.Background())

sigCh := make(chan os.Signal, 1)

signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)

go func() {

<-sigCh // Wait for interrupt signal to gracefully shutdown

<-sigCh // Wait for interrupt signal to gracefully shutdown
cancel() // Notify each goroutine and wait them stopped

}()

nf, err := service.NewApp(ctx, cfg, tlsKeyLogPath)

if err != nil {

return err

}

NF = nf

nf.Start()

return nil

}

func initLogFile(logNfPath []string) (string, error) {

logTlsKeyPath := ""

for _, path := range logNfPath {

if err := logger_util.LogFileHook(logger.Log, path); err != nil {

return "", err

}

if logTlsKeyPath != "" {

continue

}

nfDir, _ := filepath.Split(path)

tmpDir := filepath.Join(nfDir, "key")

if err := os.MkdirAll(tmpDir, 0o775); err != nil {

logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err)

return "", err

}

_, name := filepath.Split(factory.NfDefaultTLSKeyLogPath)

logTlsKeyPath = filepath.Join(tmpDir, name)

}

return logTlsKeyPath, nil

}
69 changes: 15 additions & 54 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,90 +11,51 @@ import (
)

type NFContext struct {
NfId string

Name string

UriScheme models.UriScheme

BindingIPv4 string

SBIPort int

NfId string
Name string
UriScheme models.UriScheme
BindingIPv4 string
SBIPort int
SpyFamilyData map[string]string
}

var nfContext = NFContext{}

func InitNfContext() {

cfg := factory.NfConfig

nfContext.NfId = uuid.New().String()

nfContext.Name = "ANYA"

nfContext.UriScheme = cfg.Configuration.Sbi.Scheme

nfContext.SBIPort = cfg.Configuration.Sbi.Port

nfContext.BindingIPv4 = os.Getenv(cfg.Configuration.Sbi.BindingIPv4)

if nfContext.BindingIPv4 != "" {

logger.CtxLog.Info("Parsing ServerIPv4 address from ENV Variable.")

} else {

nfContext.BindingIPv4 = cfg.Configuration.Sbi.BindingIPv4

if nfContext.BindingIPv4 == "" {

logger.CtxLog.Warn("Error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default.")

nfContext.BindingIPv4 = "0.0.0.0"

}

}

nfContext.SpyFamilyData = map[string]string{

"Loid": "Forger",

"Anya": "Forger",

"Yor": "Forger",

"Bond": "Forger",

"Becky": "Blackbell",

"Loid": "Forger",
"Anya": "Forger",
"Yor": "Forger",
"Bond": "Forger",
"Becky": "Blackbell",
"Damian": "Desmond",

"Franky": "Franklin",

"Fiona": "Frost",

"Fiona": "Frost",
"Sylvia": "Sherwood",

"Yuri": "Briar",

"Yuri": "Briar",
"Millie": "Manis",

"Ewen": "Egeburg",

"Emile": "Elman",

"Henry": "Henderson",

"Ewen": "Egeburg",
"Emile": "Elman",
"Henry": "Henderson",
"Martha": "Marriott",
}

}

func GetSelf() *NFContext {

return &nfContext

}
31 changes: 6 additions & 25 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,27 @@ import (
)

var (
Log *logrus.Logger

NfLog *logrus.Entry

Log *logrus.Logger
NfLog *logrus.Entry
MainLog *logrus.Entry

InitLog *logrus.Entry

CfgLog *logrus.Entry

CtxLog *logrus.Entry

GinLog *logrus.Entry

SBILog *logrus.Entry
CfgLog *logrus.Entry
CtxLog *logrus.Entry
GinLog *logrus.Entry
SBILog *logrus.Entry
)

func init() {

fieldsOrder := []string{

logger_util.FieldNF,

logger_util.FieldCategory,
}

Log = logger_util.New(fieldsOrder)

NfLog = Log.WithField(logger_util.FieldNF, "ANYA")

MainLog = NfLog.WithField(logger_util.FieldCategory, "Main")

InitLog = NfLog.WithField(logger_util.FieldCategory, "Init")

CfgLog = NfLog.WithField(logger_util.FieldCategory, "CFG")

CtxLog = NfLog.WithField(logger_util.FieldCategory, "CTX")

GinLog = NfLog.WithField(logger_util.FieldCategory, "GIN")

SBILog = NfLog.WithField(logger_util.FieldCategory, "SBI")

}
47 changes: 4 additions & 43 deletions internal/sbi/api_chiikawa.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,47 @@ import (
)

func (s *Server) getChiikawaRoute() []Route {

return []Route{

{

Name: "Yee~ya~ha!",

Method: http.MethodGet,

Name: "Yee~ya~ha!",
Method: http.MethodGet,
Pattern: "/",

APIFunc: s.YeeYaHa,

// Use

// curl -X GET http://127.0.0.163:8000/chiikawa/ -w "\n"

},

{

Name: "Create Chiikawa Character",

Method: http.MethodPost,

Name: "Create Chiikawa Character",
Method: http.MethodPost,
Pattern: "/print",

APIFunc: s.PrintChiikawa,

// Use

// curl -X POST http://127.0.0.163:8000/chiikawa/print -w "\n"

},
}

}

func (s *Server) YeeYaHa(c *gin.Context) {

c.String(http.StatusOK, "Yee~ya~ha!")

}

func (s *Server) PrintChiikawa(c *gin.Context) {

c.String(http.StatusOK, `.............................&... /*...&... //..................................
...............%.............@... &...&.. &...................,...............
................/.............&.. &..(,.. @,..................,................
............... *............ &.. &.(/.. &&...............%&%,................
......... .... /////*,.. ...& .&@ .%#* #@&&&/.. .%.........* ............
...........% . .. . @@ *& . .. .... .& ...& ...
* ... ,( & @ @ & . ... . &.....
.. %% & ( & &. * & .
. # .@ @ %&@ *&&@ @# # ..#
( @ &&&&& &&&&% & %
# @ .,.., / .,.(/.. #/ %
% @ *,@..,. @@&&& .,..,.. (* .,
. & &*/ & ,
. * @ .*. @ %
( &, .&&&*,/@% & .*/##%&,&&%%%&&%#
%%%%%&&%#(/*. *,&@ &. .&&( #&*&&
. . @ %&(*/#@&&/ &
& @. `)

}
Loading

0 comments on commit 332e789

Please sign in to comment.