初始化
Build docker and publish / prepare (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.admin image_name:ppanel-admin name:admin]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.api image_name:ppanel-api name:api]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.node image_name:ppanel-node name:node]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.queue image_name:ppanel-queue name:queue]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.scheduler image_name:ppanel-scheduler name:scheduler]) (push) Has been cancelled
Build docker and publish / deploy (push) Has been cancelled
Build docker and publish / notify (push) Has been cancelled
Build docker and publish / prepare (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.admin image_name:ppanel-admin name:admin]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.api image_name:ppanel-api name:api]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.node image_name:ppanel-node name:node]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.queue image_name:ppanel-queue name:queue]) (push) Has been cancelled
Build docker and publish / build (map[dockerfile:deploy/Dockerfile.scheduler image_name:ppanel-scheduler name:scheduler]) (push) Has been cancelled
Build docker and publish / deploy (push) Has been cancelled
Build docker and publish / notify (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "节点服务公共接口"
|
||||
)
|
||||
|
||||
@server (
|
||||
prefix: /api/v1/node
|
||||
group: common
|
||||
)
|
||||
service ppanelnode {
|
||||
@handler HealthHandler
|
||||
get /health returns (HealthResp)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "节点通信接口"
|
||||
)
|
||||
|
||||
type (
|
||||
PushStatusReq {
|
||||
CPU float64 `json:"cpu"`
|
||||
Mem float64 `json:"mem"`
|
||||
Disk float64 `json:"disk"`
|
||||
OnlineUsers int `json:"online_users"`
|
||||
Uptime int64 `json:"uptime"`
|
||||
}
|
||||
|
||||
UserTraffic {
|
||||
UserId int64 `json:"user_id"`
|
||||
Upload int64 `json:"upload"`
|
||||
Download int64 `json:"download"`
|
||||
}
|
||||
|
||||
PushUserTrafficReq {
|
||||
Data []UserTraffic `json:"data"`
|
||||
}
|
||||
|
||||
OnlineUser {
|
||||
UserId int64 `json:"user_id"`
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
|
||||
PushOnlineUsersReq {
|
||||
Data []OnlineUser `json:"data"`
|
||||
}
|
||||
|
||||
ServerConfigResp {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Protocol string `json:"protocol"`
|
||||
Config map[string]string `json:"config"`
|
||||
}
|
||||
|
||||
ServerUserResp {
|
||||
Id int64 `json:"id"`
|
||||
Token string `json:"token"`
|
||||
Speed int64 `json:"speed"`
|
||||
DeviceLimit int `json:"device_limit"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
prefix: /api/v1/node
|
||||
group: node
|
||||
middleware: NodeAuthMiddleware
|
||||
)
|
||||
service ppanelnode {
|
||||
@handler GetServerConfigHandler
|
||||
get /config returns (ServerConfigResp)
|
||||
|
||||
@handler GetServerUserListHandler
|
||||
get /users returns ([]ServerUserResp)
|
||||
|
||||
@handler PushStatusHandler
|
||||
post /status (PushStatusReq)
|
||||
|
||||
@handler PushUserTrafficHandler
|
||||
post /traffic (PushUserTrafficReq)
|
||||
|
||||
@handler PushOnlineUsersHandler
|
||||
post /online (PushOnlineUsersReq)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "节点服务公共类型"
|
||||
)
|
||||
|
||||
type (
|
||||
HealthResp {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
Name: zero-ppanel-node
|
||||
Host: 0.0.0.0
|
||||
Port: 8082
|
||||
Mode: dev
|
||||
|
||||
Log:
|
||||
Mode: console
|
||||
Encoding: plain
|
||||
Level: debug
|
||||
|
||||
Telemetry:
|
||||
Name: zero-ppanel-node
|
||||
Endpoint: 127.0.0.1:4318
|
||||
Sampler: 1.0
|
||||
Batcher: otlphttp
|
||||
|
||||
DevServer:
|
||||
Enabled: true
|
||||
Port: 6162
|
||||
EnableMetrics: true
|
||||
EnablePprof: true
|
||||
|
||||
NodeSecret: "dev-node-secret"
|
||||
|
||||
MySQL:
|
||||
DataSource: "root:password@tcp(127.0.0.1:3306)/ppanel?charset=utf8mb4&parseTime=true"
|
||||
|
||||
Redis:
|
||||
Host: 127.0.0.1:6379
|
||||
Type: node
|
||||
@@ -0,0 +1,34 @@
|
||||
Name: zero-ppanel-node
|
||||
Host: 0.0.0.0
|
||||
Port: 8082
|
||||
Mode: pro
|
||||
|
||||
Log:
|
||||
Mode: file
|
||||
Encoding: json
|
||||
Level: info
|
||||
Path: /var/log/zero-ppanel/node
|
||||
KeepDays: 15
|
||||
Rotation: daily
|
||||
|
||||
Telemetry:
|
||||
Name: zero-ppanel-node
|
||||
Endpoint: http://jaeger:4318/v1/traces
|
||||
Sampler: 0.1
|
||||
Batcher: otlphttp
|
||||
|
||||
DevServer:
|
||||
Enabled: true
|
||||
Port: 6162
|
||||
EnableMetrics: true
|
||||
EnablePprof: false
|
||||
|
||||
NodeSecret: "${NODE_SECRET}"
|
||||
|
||||
MySQL:
|
||||
DataSource: "${MYSQL_DSN}"
|
||||
|
||||
Redis:
|
||||
Host: "${REDIS_HOST}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASS}"
|
||||
@@ -0,0 +1,32 @@
|
||||
Name: zero-ppanel-node
|
||||
Host: 0.0.0.0
|
||||
Port: 8082
|
||||
Mode: test
|
||||
|
||||
Log:
|
||||
Mode: file
|
||||
Encoding: json
|
||||
Level: info
|
||||
Path: logs/node
|
||||
KeepDays: 7
|
||||
|
||||
Telemetry:
|
||||
Name: zero-ppanel-node
|
||||
Endpoint: http://jaeger:4318/v1/traces
|
||||
Sampler: 0.5
|
||||
Batcher: otlphttp
|
||||
|
||||
DevServer:
|
||||
Enabled: true
|
||||
Port: 6162
|
||||
EnableMetrics: true
|
||||
EnablePprof: true
|
||||
|
||||
NodeSecret: "test-node-secret"
|
||||
|
||||
MySQL:
|
||||
DataSource: "root:password@tcp(mysql:3306)/ppanel?charset=utf8mb4&parseTime=true"
|
||||
|
||||
Redis:
|
||||
Host: redis:6379
|
||||
Type: node
|
||||
@@ -0,0 +1,3 @@
|
||||
Name: ppanelnode
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
@@ -0,0 +1,10 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/common"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := common.NewHealthLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Health()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetServerConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := node.NewGetServerConfigLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetServerConfig()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetServerUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := node.NewGetServerUserListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetServerUserList()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func PushOnlineUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PushOnlineUsersReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := node.NewPushOnlineUsersLogic(r.Context(), svcCtx)
|
||||
err := l.PushOnlineUsers(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func PushStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PushStatusReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := node.NewPushStatusLogic(r.Context(), svcCtx)
|
||||
err := l.PushStatus(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func PushUserTrafficHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PushUserTrafficReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := node.NewPushUserTrafficLogic(r.Context(), svcCtx)
|
||||
err := l.PushUserTraffic(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
common "github.com/zero-ppanel/zero-ppanel/apps/node/internal/handler/common"
|
||||
node "github.com/zero-ppanel/zero-ppanel/apps/node/internal/handler/node"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/health",
|
||||
Handler: common.HealthHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/v1/node"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.NodeAuthMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/config",
|
||||
Handler: node.GetServerConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/online",
|
||||
Handler: node.PushOnlineUsersHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/status",
|
||||
Handler: node.PushStatusHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/traffic",
|
||||
Handler: node.PushUserTrafficHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/users",
|
||||
Handler: node.GetServerUserListHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/v1/node"),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type HealthLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewHealthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HealthLogic {
|
||||
return &HealthLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *HealthLogic) Health() (resp *types.HealthResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetServerConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetServerConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServerConfigLogic {
|
||||
return &GetServerConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetServerConfigLogic) GetServerConfig() (resp *types.ServerConfigResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetServerUserListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetServerUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServerUserListLogic {
|
||||
return &GetServerUserListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetServerUserListLogic) GetServerUserList() (resp []types.ServerUserResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PushOnlineUsersLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPushOnlineUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushOnlineUsersLogic {
|
||||
return &PushOnlineUsersLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PushOnlineUsersLogic) PushOnlineUsers(req *types.PushOnlineUsersReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PushStatusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPushStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushStatusLogic {
|
||||
return &PushStatusLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PushStatusLogic) PushStatus(req *types.PushStatusReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PushUserTrafficLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPushUserTrafficLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushUserTrafficLogic {
|
||||
return &PushUserTrafficLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PushUserTrafficLogic) PushUserTraffic(req *types.PushUserTrafficReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package middleware
|
||||
|
||||
import "net/http"
|
||||
|
||||
type NodeAuthMiddleware struct {
|
||||
}
|
||||
|
||||
func NewNodeAuthMiddleware() *NodeAuthMiddleware {
|
||||
return &NodeAuthMiddleware{}
|
||||
}
|
||||
|
||||
func (m *NodeAuthMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO generate middleware implement function, delete after code implementation
|
||||
|
||||
// Passthrough to next handler if need
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/config"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/middleware"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
NodeAuthMiddleware rest.Middleware
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
NodeAuthMiddleware: middleware.NewNodeAuthMiddleware().Handle,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
|
||||
package types
|
||||
|
||||
type HealthResp struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type OnlineUser struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
|
||||
type PushOnlineUsersReq struct {
|
||||
Data []OnlineUser `json:"data"`
|
||||
}
|
||||
|
||||
type PushStatusReq struct {
|
||||
CPU float64 `json:"cpu"`
|
||||
Mem float64 `json:"mem"`
|
||||
Disk float64 `json:"disk"`
|
||||
OnlineUsers int `json:"online_users"`
|
||||
Uptime int64 `json:"uptime"`
|
||||
}
|
||||
|
||||
type PushUserTrafficReq struct {
|
||||
Data []UserTraffic `json:"data"`
|
||||
}
|
||||
|
||||
type ServerConfigResp struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Protocol string `json:"protocol"`
|
||||
Config map[string]string `json:"config"`
|
||||
}
|
||||
|
||||
type ServerUserResp struct {
|
||||
Id int64 `json:"id"`
|
||||
Token string `json:"token"`
|
||||
Speed int64 `json:"speed"`
|
||||
DeviceLimit int `json:"device_limit"`
|
||||
}
|
||||
|
||||
type UserTraffic struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
Upload int64 `json:"upload"`
|
||||
Download int64 `json:"download"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "PPanel Node"
|
||||
desc: "节点通信服务"
|
||||
author: "ppanel"
|
||||
version: "1.0"
|
||||
)
|
||||
|
||||
import (
|
||||
"desc/types.api"
|
||||
"desc/common.api"
|
||||
"desc/node.api"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/config"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/handler"
|
||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/node-dev.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
Reference in New Issue
Block a user