🎉 start the project
This commit is contained in:
12
internal/handler/available.go
Normal file
12
internal/handler/available.go
Normal file
@ -0,0 +1,12 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/loveuer/nf"
|
||||
"github.com/loveuer/nf/nft/resp"
|
||||
"github.com/loveuer/nfflow/internal/opt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Available(c *nf.Ctx) error {
|
||||
return resp.Resp200(c, nf.Map{"ok": true, "time": time.Now(), "version": opt.Version})
|
||||
}
|
51
internal/handler/new_input.go
Normal file
51
internal/handler/new_input.go
Normal file
@ -0,0 +1,51 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/loveuer/nf"
|
||||
"github.com/loveuer/nf/nft/resp"
|
||||
"github.com/loveuer/nfflow/internal/inputs/es7"
|
||||
"github.com/loveuer/nfflow/internal/util"
|
||||
)
|
||||
|
||||
func NewInput_ES7(c *nf.Ctx) error {
|
||||
type Req struct {
|
||||
Endpoints []string `json:"endpoints"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
CA string `json:"ca"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
)
|
||||
|
||||
if err = c.BodyParser(req); err != nil {
|
||||
return resp.Resp400(c, err.Error())
|
||||
}
|
||||
|
||||
if len(req.Endpoints) == 0 {
|
||||
return resp.Resp400(c, req)
|
||||
}
|
||||
|
||||
cli := &es7.Client{
|
||||
Endpoints: req.Endpoints,
|
||||
Username: req.Username,
|
||||
Password: req.Password,
|
||||
CA: req.CA,
|
||||
}
|
||||
|
||||
if err = cli.InitClient(util.Timeout(5)); err != nil {
|
||||
return resp.Resp400(c, err.Error(), "连接失败, 请检查配置")
|
||||
}
|
||||
|
||||
if err = cli.Ping(util.Timeout(3)); err != nil {
|
||||
return resp.Resp400(c, err.Error(), "尝试连接失败, 请检查配置")
|
||||
}
|
||||
|
||||
if cli.Save(util.Timeout(5)); err != nil {
|
||||
return resp.Resp500(c, err.Error())
|
||||
}
|
||||
|
||||
return resp.Resp200(c, nil, "保存 输入流 成功")
|
||||
}
|
Reference in New Issue
Block a user