Skip to content

Commit 7a043c1

Browse files
committed
feat:send verify code
1 parent dc5a80d commit 7a043c1

18 files changed

Lines changed: 887 additions & 10 deletions

File tree

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM golang:1.21.13-bookworm AS builder
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends wget unzip git \
4+
build-essential \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
ARG GH_CI_USER=$GH_CI_USER
8+
ARG GH_CI_TOKEN=$GH_CI_TOKEN
9+
ARG GL_CI_USER=$GL_CI_USER
10+
ARG GL_CI_TOKEN=$GL_CI_TOKEN
11+
12+
COPY . /build
13+
WORKDIR /build
14+
RUN make build
15+
16+
FROM registry.tespkg.in/library/debian:bookworm-slim
17+
18+
RUN apt-get update && \
19+
apt-get install -y --no-install-recommends ca-certificates libaio1 && \
20+
update-ca-certificates && \
21+
rm -rf /var/lib/apt/lists/*
22+
23+
COPY --from=builder /build/bin/bytes-be /app/bytes-be
24+
COPY contrib/server.yaml /app/contrib/server.yaml
25+
26+
WORKDIR /app
27+
CMD [ "/app/bytes-be", "staff", "-c", "/app/contrib/server.yaml" ]

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
GH_CI_USER:=$(GH_CI_USER)
3+
GH_CI_TOKEN:=$(GH_CI_TOKEN)
4+
GL_CI_USER:=$(GL_CI_USER)
5+
GL_CI_TOKEN:=$(GL_CI_TOKEN)
6+
7+
.PHONY: settoken
8+
settoken:
9+
ifneq ('$(GH_CI_TOKEN)','')
10+
@git config --global url."https://$(GH_CI_USER):$(GH_CI_TOKEN)@github.com/tespkg".insteadOf "https://github.com/tespkg"
11+
endif
12+
ifneq ('$(GL_CI_TOKEN)','')
13+
@git config --global url."https://$(GL_CI_USER):$(GL_CI_TOKEN)@gitlab.com/".insteadOf "https://gitlab.com/"
14+
endif
15+
16+
.PHONY: run
17+
run:
18+
@./bin/bytes-be staff -c ./contrib/server.yaml
19+
20+
.PHONY: swag
21+
swag:
22+
./bin/swag init -g main.go
23+
24+
.PHONY: build-with-vendor
25+
build-with-vendor:
26+
@if test -d "./vendor/"; then echo "checking vendor folder... [OK]"; else echo "checking vendor folder... [FAILED]"; echo "run go mod vendor first"; exit 2; fi;
27+
@mkdir -p bin
28+
@echo "start building bytes-be..."
29+
@GOPRIVATE=github.com/tespkg/*,gitlab.com/target-digital-transformation/*,tespkg.in/* go build -mod vendor -o bin/bytes-be github.com/tespkg/bytes-be
30+
@echo "building done"
31+
32+
.PHONY: build
33+
build: settoken
34+
@mkdir -p bin
35+
@echo "start building bytes-be..."
36+
@go mod tidy
37+
@GOPRIVATE=github.com/tespkg/*,gitlab.com/target-digital-transformation/*,tespkg.in/* go build -o bin/bytes-be github.com/tespkg/bytes-be
38+
@echo "building done"
39+
40+
.PHONY: build-image
41+
build-image: settoken
42+
@echo "start building docker image"
43+
@docker build -t local/bytes-be -f ./Dockerfile .
44+
@echo "building done"
45+
46+
.PHONY: build-image-with-vendor
47+
build-image-with-vendor: settoken
48+
@if test -d "./vendor/"; then echo "checking vendor folder... [OK]"; else echo "checking vendor folder... [FAILED]"; echo "run go mod vendor first"; exit 2; fi;
49+
@echo "start building docker image with vendor"
50+
@docker build -t local/bytes-be -f ./docker/vendor.Dockerfile .
51+
@echo "building done"

config/config.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package config
22

33
import (
44
"github.com/knadh/koanf"
5-
"github.com/knadh/koanf/providers/structs"
5+
"github.com/knadh/koanf/parsers/yaml"
6+
"github.com/knadh/koanf/providers/file"
67
)
78

89
type Config struct {
@@ -85,16 +86,20 @@ type BytesMatch struct {
8586
ExpireDuration int `koanf:"expire_duration"`
8687
}
8788

88-
var DefaultConfig = &Config{
89+
var DefaultConfig = Config{
8990
Version: "0.0.0",
9091
}
9192

9293
func LoadWithDefault(configPath string) (Config, error) {
93-
var cfg Config
94+
cfg := DefaultConfig
9495

9596
k := koanf.New(".")
9697

97-
if err := k.Load(structs.Provider(DefaultConfig, "koanf"), nil); err != nil {
98+
if err := k.Load(file.Provider(configPath), yaml.Parser()); err != nil {
99+
return cfg, err
100+
}
101+
102+
if err := k.Unmarshal("", &cfg); err != nil {
98103
return cfg, err
99104
}
100105

contrib/server.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ service_basic_config:
1717
bytes_env: ""
1818

1919
postgres:
20-
dsn: postgres://postgres:postgres@localhost:56565/food?sslmode=disable
20+
dsn: postgres://postgres:postgres@localhost:5432/bytes-be?sslmode=disable
2121
max_idle_conns: 100
2222
max_open_conns: 100
2323
log_level: info
@@ -35,7 +35,7 @@ redis:
3535

3636
nominatim_addr: nominatim.openstreetmap.org
3737

38-
smart_pay: ""
38+
smart_pay: "./smartpay.yml"
3939

4040
click_pay: ""
4141

docs/docs.go

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// Package docs Code generated by swaggo/swag. DO NOT EDIT
2+
package docs
3+
4+
import "github.com/swaggo/swag"
5+
6+
const docTemplate = `{
7+
"schemes": {{ marshal .Schemes }},
8+
"swagger": "2.0",
9+
"info": {
10+
"description": "{{escape .Description}}",
11+
"title": "{{.Title}}",
12+
"contact": {},
13+
"version": "{{.Version}}"
14+
},
15+
"host": "{{.Host}}",
16+
"basePath": "{{.BasePath}}",
17+
"paths": {
18+
"/api/v1/common/code/verify": {
19+
"post": {
20+
"consumes": [
21+
"application/json"
22+
],
23+
"produces": [
24+
"application/json"
25+
],
26+
"tags": [
27+
"Common"
28+
],
29+
"summary": "send verify code",
30+
"parameters": [
31+
{
32+
"description": "email",
33+
"name": "email",
34+
"in": "body",
35+
"schema": {
36+
"type": "string"
37+
}
38+
},
39+
{
40+
"description": "phone",
41+
"name": "phone",
42+
"in": "body",
43+
"schema": {
44+
"type": "string"
45+
}
46+
}
47+
],
48+
"responses": {
49+
"200": {
50+
"description": "OK",
51+
"schema": {
52+
"$ref": "#/definitions/result.ResponseSuccessBean-NullJson"
53+
}
54+
}
55+
}
56+
}
57+
},
58+
"/api/v1/customer/register": {
59+
"post": {
60+
"consumes": [
61+
"application/json"
62+
],
63+
"produces": [
64+
"application/json"
65+
],
66+
"tags": [
67+
"Customer"
68+
],
69+
"summary": "customer register",
70+
"parameters": [
71+
{
72+
"description": "customer register request",
73+
"name": "req",
74+
"in": "body",
75+
"required": true,
76+
"schema": {
77+
"$ref": "#/definitions/dto.CustomerRegisterReq"
78+
}
79+
}
80+
],
81+
"responses": {
82+
"200": {
83+
"description": "OK",
84+
"schema": {
85+
"$ref": "#/definitions/result.ResponseSuccessBean-dto_CustomerRegisterResp"
86+
}
87+
}
88+
}
89+
}
90+
}
91+
},
92+
"definitions": {
93+
"dto.CustomerRegisterReq": {
94+
"type": "object",
95+
"required": [
96+
"code",
97+
"password",
98+
"phone"
99+
],
100+
"properties": {
101+
"code": {
102+
"type": "string"
103+
},
104+
"email": {
105+
"type": "string"
106+
},
107+
"password": {
108+
"type": "string"
109+
},
110+
"phone": {
111+
"type": "string"
112+
}
113+
}
114+
},
115+
"dto.CustomerRegisterResp": {
116+
"type": "object",
117+
"properties": {
118+
"loginToken": {
119+
"type": "string"
120+
}
121+
}
122+
},
123+
"result.NullJson": {
124+
"type": "object"
125+
},
126+
"result.ResponseSuccessBean-NullJson": {
127+
"type": "object",
128+
"properties": {
129+
"code": {
130+
"type": "integer"
131+
},
132+
"data": {
133+
"$ref": "#/definitions/result.NullJson"
134+
},
135+
"msg": {
136+
"type": "string"
137+
}
138+
}
139+
},
140+
"result.ResponseSuccessBean-dto_CustomerRegisterResp": {
141+
"type": "object",
142+
"properties": {
143+
"code": {
144+
"type": "integer"
145+
},
146+
"data": {
147+
"$ref": "#/definitions/dto.CustomerRegisterResp"
148+
},
149+
"msg": {
150+
"type": "string"
151+
}
152+
}
153+
}
154+
}
155+
}`
156+
157+
// SwaggerInfo holds exported Swagger Info so clients can modify it
158+
var SwaggerInfo = &swag.Spec{
159+
Version: "",
160+
Host: "",
161+
BasePath: "",
162+
Schemes: []string{},
163+
Title: "",
164+
Description: "",
165+
InfoInstanceName: "swagger",
166+
SwaggerTemplate: docTemplate,
167+
LeftDelim: "{{",
168+
RightDelim: "}}",
169+
}
170+
171+
func init() {
172+
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
173+
}

0 commit comments

Comments
 (0)