Skip to content

Commit

Permalink
Merge pull request #198 from yoyofx/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
yoyofx authored Apr 20, 2022
2 parents 5d15243 + a2dba87 commit 3bc500e
Show file tree
Hide file tree
Showing 45 changed files with 824 additions and 135 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.15
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.18
id: go

- name: Check out code into the Go module directory
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

go.sum
__debug_bin
**/vendor/**
4 changes: 3 additions & 1 deletion abstractions/hostbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func buildingHostEnvironmentSetting(serviceCollection *dependencyinjection.Servi

hostEnv.Port = strings.Replace(hostEnv.Addr, ":", "", -1)
hostEnv.Args = os.Args
hostEnv.Profile = context.Configuration.GetProfile()
if context.Configuration != nil {
hostEnv.Profile = context.Configuration.GetProfile()
}
if hostEnv.Profile == "" {
hostEnv.Profile = hostenv.Dev
}
Expand Down
2 changes: 1 addition & 1 deletion examples/grafanaalertwebhook/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module grafanaalertwebhook
go 1.16

require (
github.com/yoyofxteam/dependencyinjection v1.0.0
github.com/yoyofx/yoyogo v0.0.0
gopkg.in/go-playground/assert.v1 v1.2.1
)

replace github.com/yoyofx/yoyogo => ../../
32 changes: 32 additions & 0 deletions examples/grafanaalertwebhook/tests/unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tests

import (
"encoding/json"
"gopkg.in/go-playground/assert.v1"
"grafanaalertwebhook/wechatrequests"
"testing"
)

func TestMessage(t *testing.T) {

var message *wechatrequests.MarkdownMessage
message = &wechatrequests.MarkdownMessage{
Markdown: struct {
Content string `json:"content" gorm:"column:content"`
}{
Content: "## " + "test" + ",请相关同事注意。\n" +
" > [报警信息] : " + "test" + "\n" +
" > [报警次数] : <font color=\"warning\">" + "0" + "次</font>" + "\n" +
" > [报警明细] : (" + "app" + ")\n",
},
Msgtype: "markdown",
}

msg, _ := json.Marshal(message)
msgStr := string(msg)

//return sendUrl + msgStr
dd := wechatrequests.PostWechatMessage("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=93fb0726-9794-49f5-b10f-dac3c85396da", msgStr)

assert.Equal(t, dd != "", true)
}
4 changes: 2 additions & 2 deletions examples/grafanaalertwebhook/wechatrequests/qiyewechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
)

func postWechatMessage(sendUrl, msg string) string {
func PostWechatMessage(sendUrl, msg string) string {
client := &http.Client{}
req, _ := http.NewRequest("POST", sendUrl, bytes.NewBuffer([]byte(msg)))
req.Header.Set("Content-Type", "application/json")
Expand Down Expand Up @@ -61,5 +61,5 @@ func SendTxtMessage(request GrafanaAlertRequest, config abstractions.IConfigurat
logger.Info("send message:%s", msgStr)

//return sendUrl + msgStr
return postWechatMessage(sendUrl, msgStr)
return PostWechatMessage(sendUrl, msgStr)
}
10 changes: 5 additions & 5 deletions examples/grpc-demo/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ yoyogo:
ttl: 30 # seconds
type: "nacos"
metadata:
url: "120.53.133.30"
port: 80
url: "47.100.213.49"
port: 8848
namespace: "public"
group: ""
cluster: ""
auth:
enable: true
username: "root"
password: "1234"
enable: false
username: "nacos"
password: "P@ssW0rd"
# type: "consul"
# metadata:
# address: "localhost:8500"
Expand Down
10 changes: 5 additions & 5 deletions examples/grpc-demo/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ yoyogo:
register-enable: false
type: "nacos"
metadata:
url: "120.53.133.30"
port: 80
url: "47.100.213.49"
port: 8848
namespace: "public"
group: ""
cluster: ""
auth:
enable: true
username: "root"
password: "1234"
enable: false
username: "nacos"
password: "P@ssW0rd"
5 changes: 2 additions & 3 deletions examples/grpc-demo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module grpc-demo
go 1.16

require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/yoyofxteam/dependencyinjection v1.0.0
github.com/yoyofx/yoyogo v0.0.0
google.golang.org/grpc v1.38.0
github.com/yoyofxteam/dependencyinjection v1.0.1
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.26.0
)

Expand Down
7 changes: 3 additions & 4 deletions examples/mvc/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module mvcdemo


go 1.16

require (
github.com/yoyofxteam/dependencyinjection v1.0.0
github.com/yoyofx/yoyogo v0.0.0
github.com/yoyofx/yoyogo v0.0.0
github.com/yoyofxteam/dependencyinjection v1.0.1
)

replace github.com/yoyofx/yoyogo => ../../
replace github.com/yoyofx/yoyogo => ../../
6 changes: 4 additions & 2 deletions examples/simpleweb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ COPY . .
WORKDIR /build/examples/simpleweb
RUN ls -a
# 将我们的代码编译成二进制可执行文件 app
RUN go mod download
RUN go build -o app .

RUN go mod download \
&& go mod tidy \
&& go build -o app .

###################
# 接下来创建一个小镜像
Expand Down
23 changes: 23 additions & 0 deletions examples/simpleweb/Dockerfile_NoCompile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine

#更新Alpine的软件源为国内源,提高下载速度
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories

RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
bash-doc \
bash-completion \
&& rm -rf /var/cache/apk/* \
&& /bin/bash
# 设置时区为上海
RUN apk -U add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata


COPY /examples/simpleweb/app /
COPY /examples/simpleweb/config_dev.yml /


ENTRYPOINT ["/app"]
8 changes: 4 additions & 4 deletions examples/simpleweb/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ yoyogo:
strategy: "round-robin" # round-robin , weight-time , random
type: "nacos"
metadata:
url: "nacos.yoyogo.run"
port: 80
url: "47.100.213.49"
port: 8848
namespace: "public"
group: "DEFAULT_GROUP"
cluster: ""
configserver:
dataId: "simple_demo"
auth:
enable: true
enable: false
username: "nacos"
password: "nacos"
password: "P@ssW0rd"
endpoint: ""
regionId: ""
accessKey: ""
Expand Down
35 changes: 26 additions & 9 deletions examples/simpleweb/contollers/usercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

type UserController struct {
mvc.ApiController
mvc.ApiController `route:"user"`

userAction models.IUserAction
discoveryClient servicediscovery.IServiceDiscovery
}
Expand All @@ -23,22 +24,29 @@ func NewUserController(userAction models.IUserAction, sd servicediscovery.IServi
}

type RegisterRequest struct {
mvc.RequestBody
UserName string `param:"UserName"`
Password string `param:"Password"`
mvc.RequestBody `route:"/v1/users/register"`

UserName string `uri:"userName"`
Password string `uri:"password"`
TestNumber uint64 `uri:"num"`
}

func (controller UserController) Register(ctx *context.HttpContext, request *RegisterRequest) mvc.ApiResult {
num := context.Query2Number[uint64](ctx, "num", "55")

fmt.Println(num)
return mvc.ApiResult{Success: true, Message: "ok", Data: request}
}

func (controller UserController) GetUserName(ctx *context.HttpContext, request *RegisterRequest) actionresult.IActionResult {
result := mvc.ApiResult{Success: true, Message: "ok", Data: request}
fmt.Println("hello world")
return actionresult.Json{Data: result}
type PostUserInfoRequest struct {
mvc.RequestBody //`route:"/{id}"`

UserName string `form:"userName" json:"userName"`
Password string `form:"password" json:"password"`
Token string `header:"Authorization" json:"token"`
}

func (controller UserController) PostUserInfo(ctx *context.HttpContext, request *RegisterRequest) actionresult.IActionResult {
func (controller UserController) PostUserInfo(ctx *context.HttpContext, request *PostUserInfoRequest) actionresult.IActionResult {
return actionresult.Json{Data: mvc.ApiResult{Success: true, Message: "ok", Data: context.H{
"user": ctx.GetUser(),
"request": request,
Expand Down Expand Up @@ -139,3 +147,12 @@ func (controller UserController) Upload(form *UploadForm) mvc.ApiResult {
})

}

func (controller UserController) TestFunc(request *struct {
mvc.RequestGET `route:"/v1/user/:id/test"`
Name string `uri:"name"`
Id uint64 `path:"id"`
}) mvc.ApiResult {

return mvc.Success(request)
}
82 changes: 78 additions & 4 deletions examples/simpleweb/go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,89 @@
module simpleweb

go 1.16
go 1.18

require (
github.com/fasthttp/websocket v1.4.3
github.com/fasthttp/websocket v1.5.0
github.com/go-sql-driver/mysql v1.6.0
github.com/jinzhu/copier v0.3.2 // indirect
github.com/yoyofx/yoyogo v0.0.0
github.com/yoyofxteam/dependencyinjection v1.0.1
github.com/yoyofxteam/reflectx v0.2.3 // indirect
gorm.io/gorm v1.21.11
)

require (
github.com/SkyAPM/go2sky v1.1.0 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emicklei/dot v0.16.0 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-redis/redis/v8 v8.11.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/copier v0.3.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.2 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/klauspost/compress v1.15.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f // indirect
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nacos-group/nacos-sdk-go v1.0.7 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.8.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 // indirect
github.com/ugorji/go/codec v1.2.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.35.0 // indirect
github.com/yoyofxteam/reflectx v0.2.3 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gorm.io/driver/mysql v1.1.1 // indirect
skywalking.apache.org/repo/goapi v0.0.0-20210401062122-a049ca15c62d // indirect
)

replace github.com/yoyofx/yoyogo => ../../
Loading

0 comments on commit 3bc500e

Please sign in to comment.