From 799b2c6628db23003ce70e5fc711826b18577bfc Mon Sep 17 00:00:00 2001 From: RIceWqy <1840169763@qq.com> Date: Mon, 18 Dec 2023 20:33:30 +0800 Subject: [PATCH] init --- README.md | 92 ++++++++++++++ apps/fushouxian-server/.processManager | 1 + apps/fushouxian-server/build.sh | 51 ++++++++ apps/fushouxian-server/config/config.json | 3 + .../config/dbconfig copy.json | 10 ++ apps/fushouxian-server/config/dbconfig.json | 10 ++ apps/fushouxian-server/config/rpaconfig.json | 5 + .../config/togocdn.client.config.json | 7 ++ apps/fushouxian-server/fushouxian-server.go | 114 ++++++++++++++++++ go.mod | 46 +++++++ 10 files changed, 339 insertions(+) create mode 100644 README.md create mode 100644 apps/fushouxian-server/.processManager create mode 100644 apps/fushouxian-server/build.sh create mode 100644 apps/fushouxian-server/config/config.json create mode 100644 apps/fushouxian-server/config/dbconfig copy.json create mode 100644 apps/fushouxian-server/config/dbconfig.json create mode 100644 apps/fushouxian-server/config/rpaconfig.json create mode 100644 apps/fushouxian-server/config/togocdn.client.config.json create mode 100644 apps/fushouxian-server/fushouxian-server.go create mode 100644 go.mod diff --git a/README.md b/README.md new file mode 100644 index 0000000..355af94 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +# digital-employee-server-go + + + +## Getting started + +To make it easy for you to get started with GitLab, here's a list of recommended next steps. + +Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! + +## Add your files + +- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files +- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: + +``` +cd existing_repo +git remote add origin http://gitlab.fanhaninfo.net/innovation/products/digital-employee-server/digital-employee-server-go.git +git branch -M main +git push -uf origin main +``` + +## Integrate with your tools + +- [ ] [Set up project integrations](http://gitlab.fanhaninfo.net/innovation/products/digital-employee-server/digital-employee-server-go/-/settings/integrations) + +## Collaborate with your team + +- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) +- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) +- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) +- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) +- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) + +## Test and Deploy + +Use the built-in continuous integration in GitLab. + +- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) +- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) +- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) +- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) +- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + +*** + +# Editing this README + +When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. + +## Suggestions for a good README +Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. + +## Name +Choose a self-explaining name for your project. + +## Description +Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. + +## Badges +On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. + +## Visuals +Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. + +## Installation +Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. + +## Usage +Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. + +## Support +Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. + +## Roadmap +If you have ideas for releases in the future, it is a good idea to list them in the README. + +## Contributing +State if you are open to contributions and what your requirements are for accepting them. + +For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. + +You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. + +## Authors and acknowledgment +Show your appreciation to those who have contributed to the project. + +## License +For open source projects, say how it is licensed. + +## Project status +If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/apps/fushouxian-server/.processManager b/apps/fushouxian-server/.processManager new file mode 100644 index 0000000..fd460de --- /dev/null +++ b/apps/fushouxian-server/.processManager @@ -0,0 +1 @@ +{"pid":42691} \ No newline at end of file diff --git a/apps/fushouxian-server/build.sh b/apps/fushouxian-server/build.sh new file mode 100644 index 0000000..e06668a --- /dev/null +++ b/apps/fushouxian-server/build.sh @@ -0,0 +1,51 @@ +case $3 in + "") + goarch="amd64" + releasePath="x86_64" + break + ;; + "arm") + goarch="arm" + releasePath="arm" + break + ;; + "arm64") + goarch="arm64" + releasePath="arm64" + break + ;; + "loong64") + goarch="loong64" + releasePath="loong64" + break + ;; + *) + echo '目标 ' $3 ' 无法编译' + exit + ;; +esac + +buildfile=$1 + + +case $2 in + "linux") echo '交叉编译目标为linux+'$goarch + echo "CGO_ENABLED=0 GOOS=linux GOARCH="$goarch" go build "$1 + CGO_ENABLED=0 GOOS=linux GOARCH=$goarch go build -o ./"${buildfile%%.*}-"$releasePath $1 + break + ;; + "windows") echo '交叉编译目标为windows+'$goarch + echo "CGO_ENABLED=0 GOOS=windows GOARCH="$goarch" go build "$1 + CGO_ENABLED=0 GOOS=windows GOARCH=$goarch go build -o ././"${buildfile%%.*}-"$releasePath".exe" $1 + break + ;; + "darwin") echo '交叉编译目标为maxos+'$goarch + echo "CGO_ENABLED=0 GOOS=darwin GOARCH="$goarch" go build "$1 + CGO_ENABLED=0 GOOS=darwin GOARCH=$goarch go build -o ./"${buildfile%%.*}-"$releasePath $1 + break + ;; + *) echo '参数不正确:'$goarch + break + ;; +esac + echo '脚本执行结束...' diff --git a/apps/fushouxian-server/config/config.json b/apps/fushouxian-server/config/config.json new file mode 100644 index 0000000..62ea81d --- /dev/null +++ b/apps/fushouxian-server/config/config.json @@ -0,0 +1,3 @@ +{ + "serverport":"9001" +} diff --git a/apps/fushouxian-server/config/dbconfig copy.json b/apps/fushouxian-server/config/dbconfig copy.json new file mode 100644 index 0000000..459825a --- /dev/null +++ b/apps/fushouxian-server/config/dbconfig copy.json @@ -0,0 +1,10 @@ +[ + { + "DbType":"mysql", + "IsMaster":true, + "Dsn":"root:Password1!@tcp(mysql-a.fanhaninfo.test:3306)/dev_digital?charset=utf8mb4", + "sqlMaxIdleConns":100, + "sqlMaxOpenConns":100, + "sqlLogLevel":2 + } +] \ No newline at end of file diff --git a/apps/fushouxian-server/config/dbconfig.json b/apps/fushouxian-server/config/dbconfig.json new file mode 100644 index 0000000..5524858 --- /dev/null +++ b/apps/fushouxian-server/config/dbconfig.json @@ -0,0 +1,10 @@ +[ + { + "DbType":"mssql", + "IsMaster":true, + "Dsn":"server=172.0.0.8;user id=sa;password=Password1!;database=DIGITAL", + "sqlMaxIdleConns":1, + "sqlMaxOpenConns":1, + "sqlLogLevel":2 + } +] \ No newline at end of file diff --git a/apps/fushouxian-server/config/rpaconfig.json b/apps/fushouxian-server/config/rpaconfig.json new file mode 100644 index 0000000..171003c --- /dev/null +++ b/apps/fushouxian-server/config/rpaconfig.json @@ -0,0 +1,5 @@ +{ + "rpa_url": "http://172.0.0.19:19005", + "username": "admin", + "password": "123" +} diff --git a/apps/fushouxian-server/config/togocdn.client.config.json b/apps/fushouxian-server/config/togocdn.client.config.json new file mode 100644 index 0000000..41a1e8f --- /dev/null +++ b/apps/fushouxian-server/config/togocdn.client.config.json @@ -0,0 +1,7 @@ +{ + "Priority":100, + "ModuleName":"digital-employee-server-go", + "ServerUrls":[ + "ws://172.0.0.19:19000/websocket/jsonrpc" + ] +} diff --git a/apps/fushouxian-server/fushouxian-server.go b/apps/fushouxian-server/fushouxian-server.go new file mode 100644 index 0000000..fe72f38 --- /dev/null +++ b/apps/fushouxian-server/fushouxian-server.go @@ -0,0 +1,114 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" + _ "src/init" + + "gitlab.fanhaninfo.net/go/togo/dao/basedboperat" + "gitlab.fanhaninfo.net/go/togo/dao/ormDriver/gormDriver" + "gitlab.fanhaninfo.net/go/togo/dao/ormDriver/xormDriver" + "gitlab.fanhaninfo.net/go/togo/lib/jsonrpc" + "gitlab.fanhaninfo.net/go/togo/lib/processmanager" + "gitlab.fanhaninfo.net/go/togo/lib/system" +) + +var appName string = "fushouxian-server" +var appVersion string = "1.0.0" + +var basePath = system.GetPathOfProgram() + +func init() { + //初始化xorm数据库驱动 + var dbconfig []xormDriver.DsnConfig + system.ScanConfigJson(basePath+"/config/dbconfig.json", &dbconfig) + xormDriver.New(dbconfig) + + //初始化gorm数据库驱动 + var gormdbconfig []gormDriver.DsnConfig + system.ScanConfigJson(basePath+"/config/dbconfig.json", &gormdbconfig) + gormDriver.New(gormdbconfig) + + //设定默认orm引擎 + err := basedboperat.SetOrmEngine("xorm") + if err != nil { + log.Print(err.Error()) + } + +} +func main() { + pm := processmanager.GetManager() + for k, v := range os.Args { + switch v { + case "start": + if k == 1 { + if pm.Start() { + log.Print("启动成功") + start() + return + } else { + log.Print("启动失败:" + pm.Error.Error()) + return + } + } + case "restart": + if k == 1 { + if pm.ReStart() { + log.Print("重启成功") + start() + return + } else { + log.Print("重启失败:" + pm.Error.Error()) + } + return + } + case "stop": + if k == 1 { + if pm.Stop() { + log.Print("程序停止成功") + } else { + log.Print("程序停止失败:程序没有运行") + } + return + } + case "version": + if k == 1 { + fmt.Print(appName + ":" + appVersion + "\n") + os.Exit(0) + } + return + + } + } + log.Print("参数传递错误,有效参数如下:\n" + os.Args[0] + " start | stop | reload | stop") + +} + +func start() { + + moduleClientInit() + + conf := struct { + Serverport string `json:"serverport"` + }{} + system.ScanConfigJson(basePath+"/config/config.json", &conf) + + http.HandleFunc("/jsonrpc", jsonrpc.HttpHandller) + + log.Print("http服务运行中:0.0.0.0:" + conf.Serverport + "\n") + http.ListenAndServe("0.0.0.0:"+conf.Serverport, nil) +} + +func moduleClientInit() { + var node jsonrpc.EdgeServerNodeConfig + system.ScanConfigJson(basePath+"config/togocdn.client.config.json", &node) + node.Methods = jsonrpc.GetMethods() + node.ModuleName = appName + for _, v := range node.ServerUrls { + node.ServerUrl = v + client := jsonrpc.NewEdgeServerNode(node) + client.Connect() + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..01a0bae --- /dev/null +++ b/go.mod @@ -0,0 +1,46 @@ +module src + +go 1.18 + +require ( + github.com/Chain-Zhang/pinyin v0.1.3 + github.com/goccy/go-json v0.10.2 + github.com/google/uuid v1.3.1 + github.com/satori/go.uuid v1.2.0 + github.com/xuri/excelize/v2 v2.8.0 + gitlab.fanhaninfo.net/go/togo v0.0.0-20230913114447-bdd05cfcdce5 +) + +require ( + github.com/go-sql-driver/mysql v1.7.1 // indirect + github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect + github.com/golang-sql/sqlexp v0.1.0 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/pgx/v5 v5.4.3 // 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/lib/pq v1.10.9 // indirect + github.com/mattn/go-sqlite3 v1.14.17 // indirect + github.com/microsoft/go-mssqldb v1.6.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/richardlehane/mscfb v1.0.4 // indirect + github.com/richardlehane/msoleps v1.0.3 // indirect + github.com/syndtr/goleveldb v1.0.0 // indirect + github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca // indirect + github.com/xuri/nfp v0.0.0-20230918160701-e5a3f5b24785 // indirect + golang.org/x/crypto v0.13.0 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/text v0.13.0 // indirect + gorm.io/driver/mysql v1.5.1 // indirect + gorm.io/driver/postgres v1.5.2 // indirect + gorm.io/driver/sqlite v1.5.3 // indirect + gorm.io/driver/sqlserver v1.5.1 // indirect + gorm.io/gorm v1.25.4 // indirect + xorm.io/builder v0.3.13 // indirect + xorm.io/xorm v1.3.3 // indirect +)