-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
107 changed files
with
3,012 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3.1' | ||
services: | ||
api-api-admin-dev: | ||
image: registry.cn-shanghai.aliyuncs.com/alice52/wpp-api-admin-go1.20.x:20240530.9953bdb | ||
restart: 'always' | ||
container_name: api-api-admin-dev | ||
volumes: | ||
- /root/wpp/api-admin/log:/app/log | ||
environment: | ||
JASYPT_ENCRYPTOR_PASSWORD: ZACK_KEY | ||
config: etc/admin-api-staging.yaml | ||
extra_hosts: | ||
- 'host.docker.internal:172.17.0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{{if .hasComment}}{{.comment}}{{end}} | ||
func (l *{{.logicName}}) {{.method}} ({{if .hasReq}}in {{.request}}{{if .stream}},stream {{.streamBody}}{{end}}{{else}}stream {{.streamBody}}{{end}}) ({{if .hasReply}}{{.response}},{{end}} error) { | ||
// todo: add your logic here and delete this line | ||
return {{if .hasReply}}&{{.responseType}}{},{{end}} nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package config | ||
|
||
import {{.authImport}} | ||
|
||
type Config struct { | ||
rest.RestConf | ||
{{.auth}} | ||
{{.jwtTrans}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package svc | ||
|
||
import ( | ||
{{.configImport}} | ||
) | ||
|
||
type ServiceContext struct { | ||
Config {{.config}} | ||
{{.middleware}} | ||
} | ||
|
||
func NewServiceContext(c {{.config}}) *ServiceContext { | ||
return &ServiceContext{ | ||
Config: c, | ||
{{.middlewareAssignment}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Name: {{.serviceName}} | ||
Host: {{.host}} | ||
Port: {{.port}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package {{.PkgName}} | ||
|
||
import ( | ||
"net/http" | ||
"github.com/micro-services-roadmap/kit-common/errorx" | ||
"github.com/micro-services-roadmap/oneid-core/modelo" | ||
|
||
"github.com/zeromicro/go-zero/rest/httpx" | ||
{{.ImportPackages}} | ||
) | ||
|
||
func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
{{if .HasRequest}}var req types.{{.RequestType}} | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.WriteJsonCtx(r.Context(), w, http.StatusBadRequest, modelo.Res(999_999, nil, err.Error())) | ||
return | ||
} | ||
|
||
{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx, r) | ||
{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}}) | ||
|
||
if err != nil { | ||
l.Logger.Errorf("Handler error: ", err) | ||
err = errorx.GrpcError(err) | ||
if v, ok := err.(*modelo.CodeError); ok { | ||
httpx.WriteJsonCtx(r.Context(), w, http.StatusBadRequest, modelo.Res(v.Code, nil, v.Error())) | ||
} else { | ||
httpx.WriteJsonCtx(r.Context(), w, http.StatusBadRequest, modelo.Res(888_888, nil, err.Error())) | ||
} | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, {{if .HasResp}}resp{{else}}nil{{end}}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package {{.pkgName}} | ||
|
||
import ( | ||
{{.imports}} | ||
"net/http" | ||
) | ||
|
||
type {{.logic}} struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
req *http.Request | ||
} | ||
|
||
{{if .hasDoc}}{{.doc}}{{end}} | ||
func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext, req *http.Request) *{{.logic}} { | ||
return &{{.logic}}{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
req: req, | ||
} | ||
} | ||
|
||
func (l *{{.logic}}) {{.function}}({{.request}}) {{.responseType}} { | ||
// todo: add your logic here and delete this line | ||
{{.returnString}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
{{.importPackages}} | ||
) | ||
|
||
var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file") | ||
|
||
func main() { | ||
flag.Parse() | ||
var c config.Config | ||
conf.MustLoad(*configFile, &c) | ||
server := rest.MustNewServer(c.RestConf) | ||
defer server.Stop() | ||
ctx := svc.NewServiceContext(c) | ||
handler.RegisterHandlers(server, ctx) | ||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) | ||
server.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package middleware | ||
|
||
import "net/http" | ||
|
||
type {{.name}} struct { | ||
} | ||
|
||
func New{{.name}}() *{{.name}} { | ||
return &{{.name}}{} | ||
} | ||
|
||
func (m *{{.name}})Handle(next http.HandlerFunc) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
// TODO generate middleware implement function, delete after code implementation | ||
// Passthrough to next handler if need | ||
next(w, r) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
server.AddRoutes( | ||
{{.routes}} {{.jwt}}{{.signature}} {{.prefix}} {{.timeout}} {{.maxBytes}} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Code generated by goctl. DO NOT EDIT. | ||
package handler | ||
|
||
import ( | ||
"net/http"{{if .hasTimeout}} | ||
"time"{{end}} | ||
|
||
{{.importPackages}} | ||
) | ||
|
||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
{{.routesAdditions}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
syntax = "v1" | ||
|
||
info ( | ||
title: // TODO: add title | ||
desc: // TODO: add description | ||
author: "{{.gitUser}}" | ||
email: "{{.gitEmail}}" | ||
) | ||
|
||
type request { | ||
// TODO: add members here and delete this comment | ||
} | ||
|
||
type response { | ||
// TODO: add members here and delete this comment | ||
} | ||
|
||
service {{.serviceName}} { | ||
@handler GetUser // TODO: set handler name and delete this comment | ||
get /users/id/:userId(request) returns(response) | ||
@handler CreateUser // TODO: set handler name and delete this comment | ||
post /users/create(request) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Code generated by goctl. DO NOT EDIT. | ||
package types{{if .containsTime}} | ||
import ( | ||
"time" | ||
){{end}} | ||
{{.types}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
FROM golang:{{.Version}}alpine AS builder | ||
|
||
LABEL stage=gobuilder | ||
|
||
ENV CGO_ENABLED 0 | ||
{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct | ||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | ||
{{end}}{{if .HasTimezone}} | ||
RUN apk update --no-cache && apk add --no-cache tzdata | ||
{{end}} | ||
WORKDIR /build | ||
|
||
ADD go.mod . | ||
ADD go.sum . | ||
RUN go mod download | ||
COPY . . | ||
{{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc | ||
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoMainFrom}} | ||
|
||
|
||
FROM {{.BaseImage}} | ||
|
||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
{{if .HasTimezone}}COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}} | ||
ENV TZ {{.Timezone}} | ||
{{end}} | ||
WORKDIR /app | ||
COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}{{if .Argument}} | ||
COPY --from=builder /app/etc /app/etc{{end}} | ||
{{if .HasPort}} | ||
EXPOSE {{.Port}} | ||
{{end}} | ||
CMD ["./{{.ExeFile}}"{{.Argument}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Name: gateway-example # gateway name | ||
Host: localhost # gateway host | ||
Port: 8888 # gateway port | ||
Upstreams: # upstreams | ||
- Grpc: # grpc upstream | ||
Target: 0.0.0.0:8080 # grpc target,the direct grpc server address,for only one node | ||
# Endpoints: [0.0.0.0:8080,192.168.120.1:8080] # grpc endpoints, the grpc server address list, for multiple nodes | ||
# Etcd: # etcd config, if you want to use etcd to discover the grpc server address | ||
# Hosts: [127.0.0.1:2378,127.0.0.1:2379] # etcd hosts | ||
# Key: greet.grpc # the discovery key | ||
# protoset mode | ||
ProtoSets: | ||
- hello.pb | ||
# Mappings can also be written in proto options | ||
# Mappings: # routes mapping | ||
# - Method: get | ||
# Path: /ping | ||
# RpcPath: hello.Hello/Ping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
|
||
"github.com/zeromicro/go-zero/core/conf" | ||
"github.com/zeromicro/go-zero/gateway" | ||
) | ||
|
||
var configFile = flag.String("f", "etc/gateway.yaml", "config file") | ||
|
||
func main() { | ||
flag.Parse() | ||
var c gateway.GatewayConf | ||
conf.MustLoad(*configFile, &c) | ||
gw := gateway.MustNewServer(c) | ||
defer gw.Stop() | ||
gw.Start() | ||
} |
Oops, something went wrong.