🎉 start the project

This commit is contained in:
loveuer
2024-03-29 18:05:09 +08:00
commit 96844d25d6
18 changed files with 403 additions and 0 deletions

34
internal/cmd/root.go Normal file
View File

@ -0,0 +1,34 @@
package cmd
import (
"fmt"
"github.com/loveuer/nfflow/internal/opt"
"github.com/loveuer/nfflow/internal/srv"
"github.com/spf13/cobra"
)
var (
version bool
root = &cobra.Command{
Use: "nfflow",
Run: func(cmd *cobra.Command, args []string) {
if version {
fmt.Printf("nfflow \nVersion: %s\n", opt.Version)
}
},
}
run = &cobra.Command{
Use: "run",
Example: "nfflow run --address ':80'",
RunE: func(cmd *cobra.Command, args []string) error {
return srv.Run(cmd.Context())
},
}
)
func init() {
root.Flags().BoolVarP(&version, "version", "v", false, "print version")
run.Flags().StringVar(&opt.Cfg.Address, "address", ":80", "service listen address")
root.AddCommand(run)
}

13
internal/cmd/run.go Normal file
View File

@ -0,0 +1,13 @@
package cmd
import (
"context"
"github.com/sirupsen/logrus"
)
func Run(ctx context.Context) {
if err := root.ExecuteContext(ctx); err != nil {
logrus.Debugf("cmd.Run: execute with err=%v", err)
return
}
}