🎉 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

22
internal/srv/api.go Normal file
View File

@ -0,0 +1,22 @@
package srv
import (
"github.com/loveuer/nf"
"github.com/loveuer/nfflow/internal/handler"
)
func initApp() *nf.App {
engine := nf.New()
app := engine.Group("/api")
app.Get("/available", handler.Available)
{
api := app.Group("/new")
inputApi := api.Group("/input")
inputApi.Post("/es7", handler.NewInput_ES7)
}
return engine
}

39
internal/srv/run.go Normal file
View File

@ -0,0 +1,39 @@
package srv
import (
"context"
"github.com/loveuer/nfflow/internal/opt"
"github.com/loveuer/nfflow/internal/util"
"github.com/sirupsen/logrus"
"net"
)
func Run(ctx context.Context) error {
app := initApp()
ln, err := net.Listen("tcp", opt.Cfg.Address)
if err != nil {
logrus.Errorf("srv.Run: err=%v", err)
return err
}
ready := make(chan bool)
go func() {
ready <- true
<-ctx.Done()
if err = app.Shutdown(util.Timeout(2)); err != nil {
logrus.Infof("srv.Run: nf app shutdown err=%v", err)
}
}()
<-ready
if err = app.RunListener(ln); err != nil {
logrus.Errorf("srv.Run: nf app run err=%v", err)
return err
}
return nil
}