feat jenkins cicd
This commit is contained in:
@@ -7,7 +7,7 @@ public class PlayerManager : MonoBehaviour
|
||||
public GameObject playerPrefab;
|
||||
public Transform playerScene;
|
||||
|
||||
private Dictionary<int, PlayerMove> _players = new();
|
||||
private Dictionary<long, PlayerMove> _players = new();
|
||||
|
||||
public static PlayerManager Instance { get; private set; }
|
||||
|
||||
@@ -32,10 +32,10 @@ public class PlayerManager : MonoBehaviour
|
||||
private GameObject AddPlayer(PositionInfo info)
|
||||
{
|
||||
var player = Instantiate(playerPrefab, playerScene);
|
||||
player.GetComponent<PlayerInfo>().uid = info.UID;
|
||||
player.GetComponent<PlayerInfo>().usn = info.USN;
|
||||
var move = player.GetComponent<PlayerMove>();
|
||||
move.SetPosition(info.X, info.Y);
|
||||
_players.Add(info.UID, move);
|
||||
_players.Add(info.USN, move);
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ public class PlayerManager : MonoBehaviour
|
||||
var position = S2C_Position.Parser.ParseFrom(msg);
|
||||
foreach (var info in position.Info)
|
||||
{
|
||||
if (!_players.ContainsKey(info.UID))
|
||||
if (!_players.ContainsKey(info.USN))
|
||||
{
|
||||
AddPlayer(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
_players[info.UID].SetPosition(info.X, info.Y);
|
||||
_players[info.USN].SetPosition(info.X, info.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public class SocketManager : MonoBehaviour
|
||||
|
||||
public async void Connect()
|
||||
{
|
||||
// _ws = new WebSocket($"wss://www.hlsq.asia/ws/?token={Random.Range(1, 1000)}");
|
||||
_ws = new WebSocket($"ws://127.0.0.1:8501/?token={Random.Range(1, 1000)}");
|
||||
_ws = new WebSocket($"wss://www.hlsq.asia/ws/?token={Random.Range(1, 1000)}");
|
||||
// _ws = new WebSocket($"ws://127.0.0.1:8501/?token={Random.Range(1, 1000)}");
|
||||
|
||||
_ws.OnOpen += () =>
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PlayerControl : MonoBehaviour
|
||||
|
||||
private void SendMoveInput(Vector2 direction)
|
||||
{
|
||||
Debug.Log($"SendMoveInput {direction} {transform.GetComponent<PlayerInfo>().uid}");
|
||||
Debug.Log($"SendMoveInput {direction} {transform.GetComponent<PlayerInfo>().usn}");
|
||||
_lastSentDirection = direction;
|
||||
_lastSendTime = Time.time;
|
||||
SocketManager.Instance.SendMessage(MessageID.Action, new C2S_Action
|
||||
|
||||
@@ -2,5 +2,5 @@ using UnityEngine;
|
||||
|
||||
public class PlayerInfo : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public int uid;
|
||||
[HideInInspector] public long usn;
|
||||
}
|
||||
@@ -19,6 +19,10 @@ db:
|
||||
connMaxLifetimeSec: 600
|
||||
connMaxIdleTimeSec: 180
|
||||
logLevel: "warn"
|
||||
redis:
|
||||
addr: "172.18.28.0:6379"
|
||||
password: "lQ7aM8oB6lK0iD5k"
|
||||
db: 0
|
||||
|
||||
serve:
|
||||
grpc:
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
docker compose -p db -f docker-compose-db.yml up -d
|
||||
docker compose -p tool -f docker-compose-tool.yml up -d
|
||||
|
||||
chown -R 1000:1000 jenkins/
|
||||
|
||||
ssh -L 2379:localhost:2379 root@47.108.184.184 yT1vU8fH5mP0rQ6h
|
||||
60
Public/Publish/doc.txt
Normal file
60
Public/Publish/doc.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
这是部署文档,记录部署需要做哪些东西
|
||||
|
||||
|
||||
frps、frpc:
|
||||
git - https://github.com/fatedier/frp
|
||||
frps启动命令(没有做成服务):nohup ./frps -c ./frps.toml &
|
||||
frpc设置成服务,开机自启:
|
||||
1. 配置文件:/etc/systemd/system/frpc.service
|
||||
[Unit]
|
||||
Description=FRP Client
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/home/pi/Desktop/frp_0.65.0_linux_arm64/frpc -c /home/pi/Desktop/frp_0.65.0_linux_arm64/frpc.toml
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
2. 启动命令:
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable frpc # 开机自启
|
||||
sudo systemctl start frpc # 立即启动
|
||||
3. 查看日志
|
||||
sudo journalctl -u frpc
|
||||
|
||||
|
||||
安装Docker
|
||||
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||
sudo sh get-docker.sh
|
||||
|
||||
Docker代理(Docker不管全局代理,必须在这里设置):
|
||||
1. 配置文件:/etc/systemd/system/docker.service.d/proxy.conf
|
||||
[Service]
|
||||
Environment="HTTP_PROXY=http://192.168.31.150:7890"
|
||||
Environment="HTTPS_PROXY=http://192.168.31.150:7890"
|
||||
Environment="NO_PROXY=localhost,127.0.0.1,.local,192.168.0.0/16"
|
||||
2. 启动命令:
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart docker
|
||||
|
||||
以下服务需要给存档权限
|
||||
sudo chown -R 1000:1000 jenkins/
|
||||
sudo chown -R 472:472 grafana/
|
||||
sudo chown -R 65534:65534 prometheus/
|
||||
sudo chown -R 1000:1000 gitea/
|
||||
|
||||
nginx auth:
|
||||
nginx验证:printf "admin:$(openssl passwd -crypt uF8uY4eM0nS9dA4iZ1bV4hE6)\n" >>./prometheus_passwd
|
||||
registry验证:htpasswd -Bbn admin pD4hC1jY1bB0pY4kF4tC > ./registry_passwd
|
||||
↑没有工具安装这个:sudo yum install -y httpd-tools
|
||||
|
||||
Jenkins账密:admin 4f848ffe54ef45eda56eebd62bc90ea0
|
||||
Grafana账密:admin pT1rA0yL0mK3iA8tJ4kE
|
||||
|
||||
ssh -L 2379:localhost:2379 root@47.108.184.184 yT1vU8fH5mP0rQ6h
|
||||
|
||||
|
||||
registry命令:
|
||||
curl -XGET -u admin:pD4hC1jY1bB0pY4kF4tC http://127.0.0.1:5000/v2/_catalog
|
||||
curl -XGET -u admin:pD4hC1jY1bB0pY4kF4tC http://127.0.0.1:5000/v2/server-gateway/tags/list
|
||||
@@ -1,8 +1,8 @@
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:latest
|
||||
image: mysql:9.5.0
|
||||
container_name: mysql
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: gR9pV4tY7zR6qL3e
|
||||
TZ: Asia/Shanghai
|
||||
@@ -12,9 +12,9 @@ services:
|
||||
- ./db/mysql:/var/lib/mysql
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
image: redis:8.4.0
|
||||
container_name: redis
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
@@ -24,7 +24,7 @@ services:
|
||||
etcd:
|
||||
image: bitnami/etcd:latest
|
||||
container_name: etcd
|
||||
restart: always
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "2379:2379"
|
||||
environment:
|
||||
|
||||
14
Public/Publish/docker-compose-gitea.yml
Normal file
14
Public/Publish/docker-compose-gitea.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
services:
|
||||
gitea:
|
||||
image: docker.gitea.com/gitea:1.25.3-rootless
|
||||
container_name: gitea
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3001:3000"
|
||||
volumes:
|
||||
- ./gitea/data:/var/lib/gitea
|
||||
- ./gitea/config:/etc/gitea
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
environment:
|
||||
- GITEA__server__ROOT_URL=http://47.108.184.184/gitea/
|
||||
35
Public/Publish/docker-compose-metric.yml
Normal file
35
Public/Publish/docker-compose-metric.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
services:
|
||||
prometheus:
|
||||
image: prom/prometheus:v3.8.1
|
||||
container_name: prometheus
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "9090:9090"
|
||||
command:
|
||||
- '--config.file=/etc/prometheus/prometheus.yml'
|
||||
volumes:
|
||||
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- ./prometheus:/prometheus
|
||||
|
||||
node_exporter:
|
||||
image: quay.io/prometheus/node-exporter:v1.10.2
|
||||
container_name: node_exporter
|
||||
command:
|
||||
- '--path.rootfs=/host'
|
||||
network_mode: host
|
||||
pid: host
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- '/:/host:ro,rslave'
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:12.3.1
|
||||
container_name: grafana
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- GF_SERVER_ROOT_URL=https://www.hlsq.asia/grafana/
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
volumes:
|
||||
- ./grafana:/var/lib/grafana
|
||||
28
Public/Publish/docker-compose-registry.yml
Normal file
28
Public/Publish/docker-compose-registry.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
services:
|
||||
registry:
|
||||
image: registry:3.0.0
|
||||
container_name: registry
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5000:5000"
|
||||
environment:
|
||||
REGISTRY_AUTH: htpasswd
|
||||
REGISTRY_AUTH_HTPASSWD_REALM: "Registry Realm"
|
||||
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
|
||||
REGISTRY_STORAGE_DELETE_ENABLED: true
|
||||
volumes:
|
||||
- ./registry/data:/var/lib/registry
|
||||
- ./registry/auth:/auth
|
||||
|
||||
registry-browser:
|
||||
image: klausmeyer/docker-registry-browser:1.9.0
|
||||
container_name: registry-browser
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8081:8080"
|
||||
environment:
|
||||
SECRET_KEY_BASE: "b8464de925141ff42cf99c702e1ff54f1997edc2761a7236a981954e0c2cd7f95bf00c77647f234e393db16b039e9ed6afc41c44ddae2d8745458c19c4ff1aa1"
|
||||
ENABLE_DELETE_IMAGES: true
|
||||
DOCKER_REGISTRY_URL: http://192.168.31.10:5000
|
||||
SCRIPT_NAME: "/browser"
|
||||
RAILS_RELATIVE_URL_ROOT: "/browser"
|
||||
@@ -1,7 +1,8 @@
|
||||
services:
|
||||
jenkins:
|
||||
image: jenkins/jenkins:lts
|
||||
image: jenkins/jenkins:2.543
|
||||
container_name: jenkins
|
||||
user: "1000:984"
|
||||
command: "--prefix=/jenkins"
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
@@ -14,7 +15,7 @@ services:
|
||||
- TZ=Asia/Shanghai
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
image: nginx:1.29.4
|
||||
container_name: nginx
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
@@ -24,33 +25,4 @@ services:
|
||||
- ./nginx/conf.d:/etc/nginx/conf.d:ro
|
||||
- ./nginx/html:/var/www/html
|
||||
- ./nginx/certs:/etc/nginx/certs:ro
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
container_name: prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
command:
|
||||
- '--config.file=/etc/prometheus/prometheus.yml'
|
||||
volumes:
|
||||
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
|
||||
node_exporter:
|
||||
image: quay.io/prometheus/node-exporter:latest
|
||||
container_name: node_exporter
|
||||
command:
|
||||
- '--path.rootfs=/host'
|
||||
network_mode: host
|
||||
pid: host
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- '/:/host:ro,rslave'
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
container_name: grafana
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- GF_SERVER_ROOT_URL=https://www.hlsq.asia/grafana/
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- ./nginx/logs:/var/log/nginx
|
||||
@@ -12,7 +12,7 @@ type LogConfig struct {
|
||||
Level string `yaml:"level"`
|
||||
}
|
||||
|
||||
type MonitorConfig struct {
|
||||
type MetricConfig struct {
|
||||
Prometheus *struct {
|
||||
Address string `yaml:"address"`
|
||||
Port int32 `yaml:"port"`
|
||||
@@ -22,6 +22,7 @@ type MonitorConfig struct {
|
||||
type DBConfig struct {
|
||||
Etcd *EtcdConfig `yaml:"etcd"`
|
||||
MySQL map[string]*MySQLConfig `yaml:"mysql"`
|
||||
Mongo map[string]*MongoConfig `yaml:"mongo"`
|
||||
Redis *RedisConfig `yaml:"redis"`
|
||||
}
|
||||
|
||||
@@ -38,6 +39,10 @@ type MySQLConfig struct {
|
||||
LogLevel string `yaml:"logLevel"`
|
||||
}
|
||||
|
||||
type MongoConfig struct {
|
||||
URI string `yaml:"uri"`
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
Addr string `yaml:"addr"`
|
||||
Password string `yaml:"password"`
|
||||
|
||||
70
Server/common/db/mongo/client.go
Normal file
70
Server/common/db/mongo/client.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"common/config"
|
||||
"common/log"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type DBName string
|
||||
|
||||
var clients = make(map[DBName]*mongo.Client)
|
||||
|
||||
func Init(cfg map[string]*config.MongoConfig) error {
|
||||
for name, oneConfig := range cfg {
|
||||
if client, err := initOneClient(oneConfig); err != nil {
|
||||
return err
|
||||
} else {
|
||||
clients[DBName(name)] = client
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func initOneClient(cfg *config.MongoConfig) (*mongo.Client, error) {
|
||||
opts := options.Client().
|
||||
ApplyURI(cfg.URI)
|
||||
|
||||
client, err := mongo.Connect(context.Background(), opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// GetClient 返回 mongo.Client,你可以通过 .Database("xxx") 获取具体数据库
|
||||
func GetClient(dbName DBName) *mongo.Client {
|
||||
if c, ok := clients[dbName]; ok {
|
||||
return c
|
||||
}
|
||||
log.Errorf("mongo client %s not found", dbName)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDB 是便捷方法,直接返回 *mongo.Database(假设 dbName 对应数据库名)
|
||||
// 如果你的配置中 dbName 和实际数据库名一致,可这样用
|
||||
func GetDB(dbName DBName) *mongo.Database {
|
||||
client := GetClient(dbName)
|
||||
if client == nil {
|
||||
return nil
|
||||
}
|
||||
// 假设配置中的 key 就是数据库名;若需分离,可在 config 中加字段
|
||||
return client.Database(string(dbName))
|
||||
}
|
||||
|
||||
func Close() error {
|
||||
if clients == nil {
|
||||
return nil
|
||||
}
|
||||
for name, client := range clients {
|
||||
if client != nil {
|
||||
if err := client.Disconnect(context.Background()); err != nil {
|
||||
log.Errorf("close mongo client %s error: %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -14,6 +14,7 @@ require (
|
||||
github.com/spf13/viper v1.21.0
|
||||
go.etcd.io/etcd/api/v3 v3.6.1
|
||||
go.etcd.io/etcd/client/v3 v3.6.1
|
||||
go.mongodb.org/mongo-driver v1.17.6
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb
|
||||
google.golang.org/grpc v1.71.1
|
||||
@@ -46,14 +47,17 @@ require (
|
||||
github.com/goccy/go-yaml v1.18.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/panjf2000/ants/v2 v2.11.3 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/quic-go/qpack v0.5.1 // indirect
|
||||
@@ -67,6 +71,10 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.6.1 // indirect
|
||||
go.uber.org/mock v0.5.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
|
||||
@@ -68,6 +68,8 @@ github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9v
|
||||
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
@@ -83,6 +85,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
@@ -97,6 +101,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/panjf2000/ants/v2 v2.11.3 h1:AfI0ngBoXJmYOpDh9m516vjqoUu2sLrIVgppI9TZVpg=
|
||||
@@ -144,14 +150,25 @@ github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA
|
||||
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
||||
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
||||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.etcd.io/etcd/api/v3 v3.6.1 h1:yJ9WlDih9HT457QPuHt/TH/XtsdN2tubyxyQHSHPsEo=
|
||||
go.etcd.io/etcd/api/v3 v3.6.1/go.mod h1:lnfuqoGsXMlZdTJlact3IB56o3bWp1DIlXPIGKRArto=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.6.1 h1:CxDVv8ggphmamrXM4Of8aCC8QHzDM4tGcVr9p2BSoGk=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.6.1/go.mod h1:aTkCp+6ixcVTZmrJGa7/Mc5nMNs59PEgBbq+HCmWyMc=
|
||||
go.etcd.io/etcd/client/v3 v3.6.1 h1:KelkcizJGsskUXlsxjVrSmINvMMga0VWwFF0tSPGEP0=
|
||||
go.etcd.io/etcd/client/v3 v3.6.1/go.mod h1:fCbPUdjWNLfx1A6ATo9syUmFVxqHH9bCnPLBZmnLmMY=
|
||||
go.mongodb.org/mongo-driver v1.17.6 h1:87JUG1wZfWsr6rIz3ZmpH90rL5tea7O3IHuSwHUpsss=
|
||||
go.mongodb.org/mongo-driver v1.17.6/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
|
||||
@@ -179,37 +196,51 @@ golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
|
||||
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
|
||||
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
|
||||
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
|
||||
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
@@ -25,6 +25,9 @@ func GenToken(usn int64, secret string, expires time.Duration) (string, error) {
|
||||
}
|
||||
|
||||
func ParseToken(tokenString string, secret string) (*Claims, error) {
|
||||
if tokenString == "" {
|
||||
return nil, errors.New("invalid token")
|
||||
}
|
||||
claims := &Claims{}
|
||||
token, err := jwt.ParseWithClaims(tokenString, claims, func(_ *jwt.Token) (interface{}, error) {
|
||||
return []byte(secret), nil
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
FROM alpine:latest
|
||||
FROM alpine:3.23.2
|
||||
|
||||
RUN apk add --no-cache tzdata && \
|
||||
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo "Asia/Shanghai" > /etc/timezone
|
||||
|
||||
COPY gateway/ /app/
|
||||
COPY server-gateway /app/server-gateway
|
||||
COPY config /app/config
|
||||
RUN chmod 777 /app/server-gateway
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
139
Server/gateway/Jenkinsfile
vendored
Normal file
139
Server/gateway/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
pipeline {
|
||||
agent none
|
||||
|
||||
environment {
|
||||
// 仓库
|
||||
REPO_URL = 'http://47.108.184.184/gitea/HuXiaoHei/Game.git'
|
||||
REPO_CREDENTIALS_ID = '80805ba2-f4ac-4d84-aee6-d4cce5fc0a96'
|
||||
|
||||
// Registry
|
||||
REGISTRY_URL = 'registry.hlsq.asia'
|
||||
REGISTRY_CREDENTIALS_ID = '0d79fc0b-a150-470b-bd0d-2639b2826031'
|
||||
|
||||
// 部署目标服务器
|
||||
SERVER_HOST = 'www.hlsq.asia'
|
||||
SERVER_USER = 'root'
|
||||
REMOTE_DIR = '/opt/apps'
|
||||
SSH_CREDENTIALS_ID = 'server-ssh-key'
|
||||
|
||||
// 基础信息
|
||||
APP_NAME = 'server-gateway'
|
||||
GO_MOD_CACHE_DIR = '/home/pi/Desktop/docker/jenkins/caches/go-mod'
|
||||
GO_BUILD_CACHE_DIR = '/home/pi/Desktop/docker/jenkins/caches/go-build'
|
||||
}
|
||||
|
||||
options {
|
||||
skipDefaultCheckout true
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
agent any
|
||||
steps {
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
branches: [[name: '*/master']],
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [],
|
||||
userRemoteConfigs: [[
|
||||
credentialsId: env.REPO_CREDENTIALS_ID,
|
||||
url: env.REPO_URL
|
||||
]]
|
||||
])
|
||||
// 立刻保存Git的Commit,避免并发问题
|
||||
script {
|
||||
def shortCommit = sh(script: 'git rev-parse --short=8 HEAD', returnStdout: true).trim()
|
||||
env.IMAGE_TAG = "${env.REGISTRY_URL}/${env.APP_NAME}:${shortCommit}"
|
||||
echo "Checked out commit: ${env.IMAGE_TAG}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Go Binary') {
|
||||
agent {
|
||||
docker {
|
||||
image 'golang:1.23.1-alpine'
|
||||
reuseNode true
|
||||
args '-u root:root -v $GO_MOD_CACHE_DIR:/go/pkg/mod -v $GO_BUILD_CACHE_DIR:/root/.cache/go-build'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir('Server/gateway') {
|
||||
sh """
|
||||
export GOPROXY=https://goproxy.cn,direct
|
||||
export CGO_ENABLED=0
|
||||
export GOOS=linux
|
||||
export GOARCH=amd64
|
||||
|
||||
go build -o ${env.APP_NAME} .
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push Docker Image') {
|
||||
agent any
|
||||
steps {
|
||||
dir('Server/gateway') {
|
||||
script {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: env.REGISTRY_CREDENTIALS_ID,
|
||||
usernameVariable: 'DOCKER_USER',
|
||||
passwordVariable: 'DOCKER_PASS'
|
||||
)]) {
|
||||
sh """
|
||||
echo "$DOCKER_PASS" | docker login --username "$DOCKER_USER" --password-stdin ${env.REGISTRY_URL}
|
||||
docker build -t ${env.IMAGE_TAG} .
|
||||
docker push ${env.IMAGE_TAG}
|
||||
docker rmi ${env.IMAGE_TAG}
|
||||
docker logout ${env.REGISTRY_URL}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stage('Deploy to Server') {
|
||||
// steps {
|
||||
// script {
|
||||
// echo "Deploying image: ${IMAGE_TAG} to ${env.SERVER_HOST}"
|
||||
//
|
||||
// sshagent (credentials: [env.SSH_CREDENTIALS_ID]) {
|
||||
// sh """
|
||||
// ssh ${env.SERVER_USER}@${env.SERVER_HOST} << 'EOF'
|
||||
// # 登录私有 registry(使用 Jenkins 注入的凭据)
|
||||
// echo "$REGISTRY_PASS" | docker login ${env.REGISTRY} --username "$REGISTRY_USER" --password-stdin
|
||||
//
|
||||
// # 拉取最新镜像
|
||||
// docker pull ${IMAGE_TAG}
|
||||
//
|
||||
// # 停止并删除旧容器(如果存在)
|
||||
// docker stop ${env.APP_NAME} 2>/dev/null || true
|
||||
// docker rm ${env.APP_NAME} 2>/dev/null || true
|
||||
//
|
||||
// # 启动新容器(根据你的需求调整端口、环境变量等)
|
||||
// docker run -d \\
|
||||
// --name ${env.APP_NAME} \\
|
||||
// --restart unless-stopped \\
|
||||
// -p 8080:8080 \\
|
||||
// ${IMAGE_TAG}
|
||||
//
|
||||
// # 可选:登出 registry
|
||||
// docker logout ${env.REGISTRY}
|
||||
// """
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
echo '✅ 构建、推送镜像与部署成功!'
|
||||
}
|
||||
failure {
|
||||
echo '❌ 构建失败,请检查日志。'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func (p *Program) Init(_ svc.Environment) error {
|
||||
p.moduleList = append(p.moduleList, &ModuleBase{})
|
||||
p.moduleList = append(p.moduleList, &ModuleDB{})
|
||||
p.moduleList = append(p.moduleList, &ModulePrometheus{})
|
||||
p.moduleList = append(p.moduleList, &ModuleGrpcGateway{})
|
||||
p.moduleList = append(p.moduleList, &ModuleWebServer{})
|
||||
p.moduleList = append(p.moduleList, &ModuleWebsocketServer{})
|
||||
p.moduleList = append(p.moduleList, &ModuleGrpcServer{})
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ func (m *ModulePrometheus) start() error {
|
||||
go func() {
|
||||
defer m.wg.Done()
|
||||
m.server = &http.Server{
|
||||
Addr: fmt.Sprintf("%v:%v", config.Get().Monitor.Prometheus.Address, config.Get().Monitor.Prometheus.Port),
|
||||
Addr: fmt.Sprintf("%v:%v", config.Get().Metric.Prometheus.Address, config.Get().Metric.Prometheus.Port),
|
||||
Handler: promhttp.Handler(),
|
||||
}
|
||||
if err := m.server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package app
|
||||
|
||||
import (
|
||||
"common/log"
|
||||
"common/net/grpc/service"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -12,20 +11,18 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ModuleGrpcGateway GrpcGateway服务模块
|
||||
type ModuleGrpcGateway struct {
|
||||
wg *sync.WaitGroup
|
||||
// 微服务列表
|
||||
services []service.IService
|
||||
server *http.Server
|
||||
// ModuleWebServer Web服务模块
|
||||
type ModuleWebServer struct {
|
||||
wg *sync.WaitGroup
|
||||
server *http.Server
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcGateway) init() error {
|
||||
func (m *ModuleWebServer) init() error {
|
||||
m.wg = &sync.WaitGroup{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcGateway) start() error {
|
||||
func (m *ModuleWebServer) start() error {
|
||||
m.wg.Add(1)
|
||||
go func() {
|
||||
defer m.wg.Done()
|
||||
@@ -41,7 +38,7 @@ func (m *ModuleGrpcGateway) start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcGateway) stop() error {
|
||||
func (m *ModuleWebServer) stop() error {
|
||||
if err := m.server.Shutdown(context.Background()); err != nil {
|
||||
log.Errorf("stop http server failed: %v", err)
|
||||
}
|
||||
@@ -8,7 +8,7 @@ log:
|
||||
maxBackups: 100
|
||||
maxAge: 7
|
||||
|
||||
monitor:
|
||||
metric:
|
||||
prometheus:
|
||||
address: "0.0.0.0"
|
||||
port: 8504
|
||||
|
||||
@@ -2,17 +2,24 @@ package config
|
||||
|
||||
import "common/config"
|
||||
|
||||
const path = "./config"
|
||||
const KeyUserAccessToken = "user:access:%v"
|
||||
const KeyUserRefreshToken = "user:refresh:%v"
|
||||
const (
|
||||
path = "./config"
|
||||
KeyUserAccessToken = "user:access:%v"
|
||||
KeyUserRefreshToken = "user:refresh:%v"
|
||||
)
|
||||
|
||||
// PublicPaths 不需要鉴权的接口,硬编码注册
|
||||
var PublicPaths = []string{
|
||||
"/user/info",
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
App *config.AppConfig `yaml:"app"`
|
||||
Log *config.LogConfig `yaml:"log"`
|
||||
Monitor *config.MonitorConfig `yaml:"monitor"`
|
||||
DB *config.DBConfig `yaml:"db"`
|
||||
Serve *config.ServeConfig `yaml:"serve"`
|
||||
Auth *struct {
|
||||
App *config.AppConfig `yaml:"app"`
|
||||
Log *config.LogConfig `yaml:"log"`
|
||||
Metric *config.MetricConfig `yaml:"metric"`
|
||||
DB *config.DBConfig `yaml:"db"`
|
||||
Serve *config.ServeConfig `yaml:"serve"`
|
||||
Auth *struct {
|
||||
Secret string `yaml:"secret"`
|
||||
Expire int64 `yaml:"expire"`
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ log:
|
||||
maxBackups: 100
|
||||
maxAge: 7
|
||||
|
||||
monitor:
|
||||
metric:
|
||||
prometheus:
|
||||
address: "0.0.0.0"
|
||||
port: 8504
|
||||
|
||||
27
Server/gateway/internal/handler/http_handler/test.go
Normal file
27
Server/gateway/internal/handler/http_handler/test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package http_handler
|
||||
|
||||
import (
|
||||
"common/net/http/http_resp"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 这个模块处理用户登录
|
||||
|
||||
type TestReq struct {
|
||||
}
|
||||
|
||||
type TestResp struct {
|
||||
Info string `json:"info"`
|
||||
}
|
||||
|
||||
func Test(c *gin.Context) {
|
||||
req := &TestReq{}
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
http_resp.JsonBadRequest(c)
|
||||
return
|
||||
}
|
||||
|
||||
http_resp.JsonOK(c, http_resp.Success(&TestResp{
|
||||
Info: "成功了",
|
||||
}))
|
||||
}
|
||||
@@ -43,24 +43,35 @@ func ginLogger(logger *zap.SugaredLogger) gin.HandlerFunc {
|
||||
|
||||
func authJwt() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
authHeader := c.GetHeader("Authorization")
|
||||
if authHeader == "" {
|
||||
// 如果是Public接口,有Token就读,没有就算了
|
||||
public := false
|
||||
for _, path := range config.PublicPaths {
|
||||
if strings.HasPrefix(c.Request.URL.Path, path) {
|
||||
public = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
token := strings.TrimPrefix(c.GetHeader("Authorization"), "Bearer ")
|
||||
if token == "" {
|
||||
if public {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
http_resp.AbortUnauthorized(c)
|
||||
return
|
||||
}
|
||||
|
||||
parts := strings.Split(authHeader, " ")
|
||||
if len(parts) != 2 || strings.ToLower(parts[0]) != "bearer" {
|
||||
http_resp.AbortUnauthorized(c)
|
||||
return
|
||||
}
|
||||
|
||||
claims, err := utils.ParseToken(parts[1], config.Get().Auth.Secret)
|
||||
claims, err := utils.ParseToken(token, config.Get().Auth.Secret)
|
||||
if err != nil {
|
||||
if public {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
http_resp.AbortUnauthorized(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 这里将Header写到请求中,grpc-gateway框架会读取然后传给grpc服务
|
||||
c.Request.Header.Set("X-Usn", strconv.Itoa(int(claims.USN)))
|
||||
c.Next()
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ func initBaseRoute(r *gin.RouterGroup) {
|
||||
g := r.Group("/gw")
|
||||
g.POST("/login", http_handler.Login)
|
||||
g.POST("/refresh_token", http_handler.RefreshToken)
|
||||
g.GET("/test", http_handler.Test)
|
||||
}
|
||||
|
||||
func initUserPath(r *gin.RouterGroup) {
|
||||
|
||||
@@ -13,9 +13,11 @@ type ModuleWebsocket struct {
|
||||
|
||||
func (p *ModuleWebsocket) init() error {
|
||||
cfg := config.Get().Client
|
||||
p.manager = ws.NewManager(
|
||||
fmt.Sprintf("%s:%d", cfg.Websocket.Address, cfg.Websocket.Port),
|
||||
)
|
||||
addr := fmt.Sprintf("%s:%d", cfg.Websocket.Address, cfg.Websocket.Port)
|
||||
if cfg.Websocket.Port == 0 {
|
||||
addr = cfg.Websocket.Address
|
||||
}
|
||||
p.manager = ws.NewManager(addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,5 +12,6 @@ client:
|
||||
count: 100
|
||||
usn: [ 1,1000000 ]
|
||||
websocket:
|
||||
address: "wss://www.hlsq.asia/ws/"
|
||||
address: "ws://47.108.184.184/ws/"
|
||||
# address: "ws://127.0.0.1"
|
||||
port: 0
|
||||
@@ -30,6 +30,7 @@ require (
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
google.golang.org/grpc v1.71.1 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
)
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI=
|
||||
google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
||||
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
||||
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
Reference in New Issue
Block a user