wip: v0.0.5

This commit is contained in:
loveuer
2025-04-27 22:14:21 +08:00
parent 25c76aebf2
commit 4801b3de08
22 changed files with 3021 additions and 3 deletions

View File

@ -1,7 +1,48 @@
package api
import "context"
import (
"context"
"github.com/loveuer/nf"
"github.com/loveuer/nf/nft/log"
"github.com/loveuer/nf/nft/tool"
"github.com/loveuer/ushare/internal/opt"
"net"
"net/http"
)
func Start(ctx context.Context) {
// TODO: implement API server start logic
func Start(ctx context.Context) <-chan struct{} {
app := nf.New(nf.Config{BodyLimit: 10 * 1024 * 1024 * 1024})
app.Get("/api/available", func(c *nf.Ctx) error {
return c.SendStatus(http.StatusOK)
})
ready := make(chan struct{})
ln, err := net.Listen("tcp", opt.Cfg.Address)
if err != nil {
log.Fatal(err.Error())
}
go func() {
ready <- struct{}{}
if err = app.RunListener(ln); err != nil {
log.Fatal(err.Error())
}
}()
<-ready
go func() {
ready <- struct{}{}
<-ctx.Done()
if err = app.Shutdown(tool.Timeout(3)); err != nil {
log.Warn(err.Error())
}
ready <- struct{}{}
}()
<-ready
return ready
}

10
internal/opt/opt.go Normal file
View File

@ -0,0 +1,10 @@
package opt
type config struct {
Debug bool
Address string
}
var (
Cfg = &config{}
)