added primitive args parsing

This commit is contained in:
Sergey Chubaryan 2024-07-27 18:07:36 +03:00
parent d2dfc7d345
commit 6a67af79b7
3 changed files with 35 additions and 0 deletions

32
args/args.go Normal file
View File

@ -0,0 +1,32 @@
package args
import (
"github.com/akamensky/argparse"
)
type Args interface {
GetConfigPath() string
}
func Parse(osArgs []string) (Args, error) {
parser := argparse.NewParser("backend", "runs backend")
s := parser.String("s", "string", &argparse.Options{Required: true, Help: "Path to a config file"})
err := parser.Parse(osArgs)
if err != nil {
return nil, err
}
return &args{
ConfigPath: *s,
}, nil
}
type args struct {
ConfigPath string
}
func (a *args) GetConfigPath() string {
return a.ConfigPath
}

1
go.mod
View File

@ -3,6 +3,7 @@ module backend
go 1.22.5
require (
github.com/akamensky/argparse v1.4.0
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.22.0
github.com/golang-jwt/jwt/v5 v5.2.1

2
go.sum
View File

@ -1,3 +1,5 @@
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc=
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
github.com/bytedance/sonic v1.11.9 h1:LFHENlIY/SLzDWverzdOvgMztTxcfcF+cqNsz9pK5zg=
github.com/bytedance/sonic v1.11.9/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=