Files
hi-server/internal/logic/admin/server/getServerProtocolsLogic.go
T
shanshanzhong147 634b5a7bd0 feat(simnet): add SimNet protocol end-to-end support
- model: SimNet protocol fields + NormalizeSimnet; type+port protocol uniqueness
- server config: OmnXT runtime config delivery via compatible() simnet case
- credentials: derive per-user psk/key_id from subscription (pkg/simnet), no new table
- subscription: adapter buildOmnxtSimnetConfigs + base64 buildOmnxtProtocolLinks + OmnXT SimNet application (migration 02161)
- UA gating: hide experimental protocols from non first-party clients (download + JSON node-list)
- admin: normalize simnet on create/update and on GET responses
- tests: 21 simnet unit tests; full suite green
2026-07-27 00:17:02 -07:00

56 lines
1.7 KiB
Go

package server
import (
"context"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type GetServerProtocolsLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Get Server Protocols
func NewGetServerProtocolsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServerProtocolsLogic {
return &GetServerProtocolsLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetServerProtocolsLogic) GetServerProtocols(req *types.GetServerProtocolsRequest) (resp *types.GetServerProtocolsResponse, err error) {
// find server
data, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, req.Id)
if err != nil {
l.Errorf("[GetServerProtocols] FindOneServer Error: %s", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[GetServerProtocols] FindOneServer Error: %s", err.Error())
}
// handler protocols
var protocols []types.Protocol
dst, err := data.UnmarshalProtocols()
if err != nil {
l.Errorf("[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
}
// Normalize simnet defaults on the response so the admin UI always sees a
// consistent config even for legacy/hand-inserted rows. dst is a fresh slice
// (not shared with the DB), so mutating it here is safe.
for i := range dst {
dst[i].NormalizeSimnet()
}
tool.DeepCopy(&protocols, dst)
return &types.GetServerProtocolsResponse{
Protocols: protocols,
}, nil
}