Compare commits
5 Commits
2a35f2f816
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a83f77b48f | |||
|
|
5ceca47d39 | ||
|
|
f62fd46939 | ||
| c7601ed174 | |||
| 8b04d7b763 |
19
.gitea/workflows/demo.yaml
Normal file
19
.gitea/workflows/demo.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name: Gitea Actions Demo
|
||||||
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Explore-Gitea-Actions:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
|
||||||
|
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||||
|
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||||
|
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
|
||||||
|
- name: List files in the repository
|
||||||
|
run: |
|
||||||
|
ls ${{ gitea.workspace }}
|
||||||
|
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||||
@@ -1,16 +1,4 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app, err := getApplication()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("应用初始化失败")
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = app.Start()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("应用启动失败")
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
//go:build wireinject
|
|
||||||
// +build wireinject
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Crimson-Gatekeeper/internal/application"
|
|
||||||
"Crimson-Gatekeeper/internal/database"
|
|
||||||
"Crimson-Gatekeeper/internal/module/userpak"
|
|
||||||
|
|
||||||
"github.com/google/wire"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getApplication() (*application.Application, error) {
|
|
||||||
wire.Build(
|
|
||||||
application.NewApplication,
|
|
||||||
database.GetDataBaseClient,
|
|
||||||
database.GetQuery,
|
|
||||||
database.GetPoolCfg,
|
|
||||||
userpak.NewUserCtl,
|
|
||||||
)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
// Code generated by Wire. DO NOT EDIT.
|
|
||||||
|
|
||||||
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
|
|
||||||
//go:build !wireinject
|
|
||||||
// +build !wireinject
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Crimson-Gatekeeper/internal/application"
|
|
||||||
"Crimson-Gatekeeper/internal/database"
|
|
||||||
"Crimson-Gatekeeper/internal/module/userpak"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Injectors from wire.go:
|
|
||||||
|
|
||||||
func getApplication() (*application.Application, error) {
|
|
||||||
db, err := database.GetDataBaseClient()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
query := database.GetQuery(db)
|
|
||||||
userCtl := userpak.NewUserCtl(query)
|
|
||||||
v := CtrlCollector(userCtl)
|
|
||||||
sqlDB, err := database.GetPoolCfg(db)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
applicationApplication := application.NewApplication(v, sqlDB)
|
|
||||||
return applicationApplication, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// wire.go:
|
|
||||||
|
|
||||||
func CtrlCollector(
|
|
||||||
c1 *userpak.UserCtl,
|
|
||||||
) []application.Ctrl {
|
|
||||||
return []application.Ctrl{c1}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package tool
|
|
||||||
|
|
||||||
// Karmaforge 因果熔炉
|
|
||||||
// 这个函数会被引用,并且最终被代码生成所重写
|
|
||||||
func Karmaforge[T any](params ...any) *T {
|
|
||||||
panic("在使用因果熔炉之前,需要执行仪式")
|
|
||||||
// var result T
|
|
||||||
// return &result
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
package lab
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package lab
|
|
||||||
|
|
||||||
type Animal interface {
|
|
||||||
sound() string
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
package lab
|
|
||||||
|
|
||||||
func main() {}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package pasture
|
|
||||||
|
|
||||||
type Dog struct {
|
|
||||||
lines string
|
|
||||||
weapon string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dog) Sound() string {
|
|
||||||
return d.lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dog) Dangers() bool {
|
|
||||||
if len(d.weapon) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDog(line string) *Dog {
|
|
||||||
return &Dog{lines: line}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package pasture
|
|
||||||
|
|
||||||
type Sheep struct {
|
|
||||||
lines string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sheep) Sound() string {
|
|
||||||
return s.lines
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSheep(line string) *Sheep {
|
|
||||||
return &Sheep{lines: line}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package tool
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"go/types"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"golang.org/x/tools/go/packages"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("无法获取当前工作目录")
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
sep := string(filepath.Separator)
|
|
||||||
s := strings.Split(pwd, sep)
|
|
||||||
var project string
|
|
||||||
for i := len(s); i > 0; i-- {
|
|
||||||
base := strings.Join(s[:i], sep)
|
|
||||||
module := filepath.Join(base, "go.mod")
|
|
||||||
_, err := os.Stat(module)
|
|
||||||
if err == nil {
|
|
||||||
project = module
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if project == "" {
|
|
||||||
panic("没有找到 go.mod ,请检查是否在 module 中调用程序")
|
|
||||||
}
|
|
||||||
project = filepath.Dir(project)
|
|
||||||
fmt.Println("当前寻根目录 " + project)
|
|
||||||
pkgs, err := packages.Load(&packages.Config{
|
|
||||||
Mode: packages.NeedName | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedSyntax | packages.NeedDeps,
|
|
||||||
Tests: false,
|
|
||||||
}, filepath.Join(project, "..."))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("解析项目失败")
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for _, pkg := range pkgs {
|
|
||||||
top := pkg.Types.Scope()
|
|
||||||
funcs := []*types.Func{}
|
|
||||||
for _, name := range top.Names() {
|
|
||||||
obj := top.Lookup(name)
|
|
||||||
if !strings.HasSuffix(obj.Name(), "Provider") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fun, ok := obj.(*types.Func)
|
|
||||||
if ok {
|
|
||||||
funcs = append(funcs, fun)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println(pkg.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Crimson-Gatekeeper/internal/common"
|
"Crimson-Gatekeeper/internal/database"
|
||||||
|
"Crimson-Gatekeeper/internal/utils"
|
||||||
|
|
||||||
"gorm.io/gen"
|
"gorm.io/gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
client, clean, _ := common.GetDataBaseClient()
|
client, err := database.GetDataBaseClient()
|
||||||
defer clean()
|
utils.PaincEro(err, "数据库链接失败")
|
||||||
g := gen.NewGenerator(gen.Config{
|
g := gen.NewGenerator(gen.Config{
|
||||||
OutPath: "./internal/query",
|
OutPath: "./internal/query",
|
||||||
ModelPkgPath: "./internal/model",
|
ModelPkgPath: "./internal/model",
|
||||||
15
srv/go.mod
15
srv/go.mod
@@ -44,14 +44,15 @@ require (
|
|||||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||||
go.uber.org/mock v0.5.0 // indirect
|
go.uber.org/mock v0.5.0 // indirect
|
||||||
golang.org/x/arch v0.20.0 // indirect
|
golang.org/x/arch v0.20.0 // indirect
|
||||||
golang.org/x/crypto v0.47.0 // indirect
|
golang.org/x/crypto v0.51.0 // indirect
|
||||||
golang.org/x/mod v0.32.0 // indirect
|
golang.org/x/mod v0.35.0 // indirect
|
||||||
golang.org/x/net v0.49.0 // indirect
|
golang.org/x/net v0.53.0 // indirect
|
||||||
golang.org/x/sync v0.19.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
golang.org/x/sys v0.40.0 // indirect
|
golang.org/x/sys v0.44.0 // indirect
|
||||||
golang.org/x/text v0.33.0 // indirect
|
golang.org/x/text v0.37.0 // indirect
|
||||||
golang.org/x/tools v0.41.0 // indirect
|
golang.org/x/tools v0.44.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.9 // indirect
|
google.golang.org/protobuf v1.36.9 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
gorm.io/datatypes v1.2.7 // indirect
|
gorm.io/datatypes v1.2.7 // indirect
|
||||||
gorm.io/driver/mysql v1.6.0 // indirect
|
gorm.io/driver/mysql v1.6.0 // indirect
|
||||||
gorm.io/hints v1.1.2 // indirect
|
gorm.io/hints v1.1.2 // indirect
|
||||||
|
|||||||
14
srv/go.sum
14
srv/go.sum
@@ -98,19 +98,33 @@ golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
|
|||||||
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||||
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
|
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
|
||||||
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
|
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
|
||||||
|
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
|
||||||
|
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
|
||||||
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
|
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
|
||||||
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
|
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
|
||||||
|
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
|
||||||
|
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
|
||||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||||
|
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
|
||||||
|
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
|
||||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
|
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
|
||||||
|
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
||||||
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
||||||
|
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||||
|
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||||
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
||||||
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
||||||
|
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
|
||||||
|
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
|
||||||
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
||||||
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
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=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ func (app *Application) Stop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApplication(ct Ctrl, p *sql.DB) *Application {
|
func NewApplication(cs []Ctrl, p *sql.DB) *Application {
|
||||||
route := gin.Default()
|
route := gin.Default()
|
||||||
|
for _, ctrl := range cs {
|
||||||
|
ctrl.RegisterRoutes(route)
|
||||||
|
}
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: ":8443",
|
Addr: ":8443",
|
||||||
Handler: route,
|
Handler: route,
|
||||||
|
|||||||
1
srv/internal/resource/database.go
Normal file
1
srv/internal/resource/database.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package resource
|
||||||
7
srv/internal/resource/init.go
Normal file
7
srv/internal/resource/init.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package resource
|
||||||
|
|
||||||
|
var cfg *Cfg
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cfg = getCfg()
|
||||||
|
}
|
||||||
65
srv/internal/resource/parse.go
Normal file
65
srv/internal/resource/parse.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package resource
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"Crimson-Gatekeeper/internal/utils"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Cfg struct {
|
||||||
|
server struct {
|
||||||
|
port string
|
||||||
|
database *struct {
|
||||||
|
host string
|
||||||
|
user string
|
||||||
|
dbname string
|
||||||
|
sslmode string
|
||||||
|
port string
|
||||||
|
passwd string
|
||||||
|
connectTimeout int
|
||||||
|
sshPoint string
|
||||||
|
}
|
||||||
|
sshPoint map[string]*struct {
|
||||||
|
host string
|
||||||
|
port int
|
||||||
|
user string
|
||||||
|
passwd string
|
||||||
|
keyPath string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCfg() *Cfg {
|
||||||
|
pwd, err := os.Getwd()
|
||||||
|
utils.PaincEro(err, "获取当前工作目录失败")
|
||||||
|
dirs, err := os.ReadDir(pwd)
|
||||||
|
utils.PaincEro(err, "获取目录文件失败")
|
||||||
|
var data []byte
|
||||||
|
for _, item := range dirs {
|
||||||
|
isyaml := strings.HasSuffix(item.Name(), ".yaml")
|
||||||
|
if isyaml {
|
||||||
|
filePath := path.Join(pwd, item.Name())
|
||||||
|
data, err = os.ReadFile(filePath)
|
||||||
|
utils.PaincEro(err, "读取配置文件失败")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data == nil {
|
||||||
|
fmt.Println("没有找到配置文件,启动失败")
|
||||||
|
panic("没有找到配置文件,进程终止")
|
||||||
|
}
|
||||||
|
cfg := &Cfg{}
|
||||||
|
err = yaml.Unmarshal(data, cfg)
|
||||||
|
utils.PaincEro(err, "解析配置文件失败")
|
||||||
|
for _, item := range cfg.server.sshPoint {
|
||||||
|
if item.port == 0 {
|
||||||
|
item.port = 22
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
25
srv/internal/resource/ssh.go
Normal file
25
srv/internal/resource/ssh.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package resource
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Crimson-Gatekeeper/internal/utils"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getSshEnv(name string) *ssh.Client {
|
||||||
|
sshCfg := cfg.server.sshPoint[name]
|
||||||
|
if sshCfg == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
clientCfg := &ssh.ClientConfig{
|
||||||
|
User: sshCfg.user,
|
||||||
|
Auth: []ssh.AuthMethod{
|
||||||
|
ssh.Password(sshCfg.passwd),
|
||||||
|
},
|
||||||
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||||
|
}
|
||||||
|
client, err := ssh.Dial("tcp", sshCfg.host+strconv.Itoa(sshCfg.port), clientCfg)
|
||||||
|
utils.PaincEro(err, "建立 SSH 隧道失败,程序中止")
|
||||||
|
return client
|
||||||
|
}
|
||||||
1
srv/internal/server/server.go
Normal file
1
srv/internal/server/server.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package server
|
||||||
10
srv/internal/utils/index.go
Normal file
10
srv/internal/utils/index.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func PaincEro(err error, msg string) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(msg)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
20
srv/server-env/config.yaml
Normal file
20
srv/server-env/config.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
server:
|
||||||
|
# 服务运行端口
|
||||||
|
port: 8443
|
||||||
|
# 数据库配置
|
||||||
|
database:
|
||||||
|
host: localhost
|
||||||
|
user: gatekeeper
|
||||||
|
dbname: crimson
|
||||||
|
sslmode: disable
|
||||||
|
port: 5432
|
||||||
|
passwd: crimson
|
||||||
|
connect-timeout: 20
|
||||||
|
ssh-point: ycy
|
||||||
|
ssh-point:
|
||||||
|
- ycy:
|
||||||
|
host: www.ciallo.pub
|
||||||
|
user: root
|
||||||
|
port: 13915
|
||||||
|
# passwd: kgmO6dGkC6hB
|
||||||
|
|
||||||
Reference in New Issue
Block a user