Skip to content

Commit a63eac7

Browse files
committed
Eric-Guo/sponge-user_server-web-http@0babfcb is applied to the generated source code, sponge is the code generator, I want to apply those change to the template on the sponge, so I will get the same result when I generate the code in future. To make it simpler, this time, you only focus on serverType == codeNameHTTP, ie. serverNameExample_httpExample. please modify the sponge template now.
1 parent 1903730 commit a63eac7

File tree

9 files changed

+454
-42
lines changed

9 files changed

+454
-42
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package initial
2+
3+
import (
4+
"github.com/go-dev-frame/sponge/internal/config"
5+
"github.com/go-dev-frame/sponge/internal/server"
6+
7+
"github.com/go-dev-frame/sponge/pkg/app"
8+
)
9+
10+
// CreateServices create http service
11+
func CreateServices() []app.IServer {
12+
var cfg = config.Get()
13+
var servers []app.IServer
14+
15+
// create a http service
16+
httpServer := server.NewHTTPServer(cfg.HTTP,
17+
server.WithHTTPIsProd(cfg.App.Env == "prod"),
18+
)
19+
servers = append(servers, httpServer)
20+
21+
return servers
22+
}

cmd/sponge/commands/generate/common.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,18 @@ func getHTTPServiceFields() []replacer.Field {
10231023
Old: appConfigFileMark3,
10241024
New: "",
10251025
},
1026+
{
1027+
Old: "serverNameExample.go.noregistry",
1028+
New: "serverNameExample.go",
1029+
},
1030+
{
1031+
Old: "createService.go.noregistry",
1032+
New: "createService.go",
1033+
},
1034+
{
1035+
Old: "http_test.go.noregistry",
1036+
New: "http_test.go",
1037+
},
10261038
{
10271039
Old: "http.go.noregistry",
10281040
New: "http.go",

cmd/sponge/commands/generate/http-pb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (g *httpPbGenerator) generateCode() (string, error) {
128128
"apis.go", "apis.swagger.json",
129129
},
130130
"internal/config": {
131-
"serverNameExample.go",
131+
"serverNameExample.go.noregistry",
132132
},
133133
"internal/ecode": {
134134
"systemCode_http.go",
@@ -137,7 +137,7 @@ func (g *httpPbGenerator) generateCode() (string, error) {
137137
"routers_pbExample.go",
138138
},
139139
"internal/server": {
140-
"http.go.noregistry", "http_option.go.noregistry",
140+
"http.go.noregistry", "http_option.go.noregistry", "http_test.go.noregistry",
141141
},
142142
}
143143

cmd/sponge/commands/generate/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (g *httpGenerator) generateCode() (string, error) {
211211
"userExample.go", "userExample_test.go",
212212
},
213213
"internal/config": {
214-
"serverNameExample.go",
214+
"serverNameExample.go.noregistry",
215215
},
216216
"internal/dao": {
217217
"userExample.go", "userExample_test.go",
@@ -232,7 +232,7 @@ func (g *httpGenerator) generateCode() (string, error) {
232232
"routers.go", "userExample.go",
233233
},
234234
"internal/server": {
235-
"http.go.noregistry", "http_option.go.noregistry",
235+
"http.go.noregistry", "http_option.go.noregistry", "http_test.go.noregistry",
236236
},
237237
"internal/types": {
238238
"swagger_types.go", "userExample_types.go",

configs/serverNameExample.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ app:
2222
# http server settings
2323
http:
2424
port: 8080 # listen port
25-
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
25+
httpsPort: 8443 # https listen port when tls is enabled
26+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
27+
idleTimeout: 60 # http idle timeout, unit(second)
28+
readTimeout: 30 # http read timeout, unit(second)
29+
writeTimeout: 30 # http write timeout, unit(second)
30+
tls:
31+
domains:
32+
- "" # list of domains for automatic tls certificates, empty disables tls
33+
acmeDirectory: "https://acme-v02.api.letsencrypt.org/directory" # acme directory url
34+
storagePath: "./storage/autocert" # directory to cache certificates
35+
eab:
36+
kid: "" # external account binding key identifier
37+
hmacKey: "" # base64url encoded external account binding hmac key
2638

2739

2840
# grpc server settings
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Code generated by https://github.com/go-dev-frame/sponge; DO NOT EDIT.
2+
3+
package config
4+
5+
import (
6+
"github.com/go-dev-frame/sponge/pkg/conf"
7+
)
8+
9+
var config *Config
10+
11+
func Init(configFile string, fs ...func()) error {
12+
config = &Config{}
13+
return conf.Parse(configFile, config, fs...)
14+
}
15+
16+
func Show(hiddenFields ...string) string {
17+
return conf.Show(config, hiddenFields...)
18+
}
19+
20+
func Get() *Config {
21+
if config == nil {
22+
panic("config is nil, please call config.Init() first")
23+
}
24+
return config
25+
}
26+
27+
func Set(conf *Config) {
28+
config = conf
29+
}
30+
31+
type Config struct {
32+
App App `yaml:"app" json:"app"`
33+
Database Database `yaml:"database" json:"database"`
34+
HTTP HTTP `yaml:"http" json:"http"`
35+
Jaeger Jaeger `yaml:"jaeger" json:"jaeger"`
36+
JWT JWT `yaml:"jwt" json:"jwt"`
37+
Logger Logger `yaml:"logger" json:"logger"`
38+
Rails Rails `yaml:"rails" json:"rails"`
39+
Redis Redis `yaml:"redis" json:"redis"`
40+
}
41+
42+
type TLS struct {
43+
AcmeDirectory string `yaml:"acmeDirectory" json:"acmeDirectory"`
44+
Domains []string `yaml:"domains" json:"domains"`
45+
Eab Eab `yaml:"eab" json:"eab"`
46+
StoragePath string `yaml:"storagePath" json:"storagePath"`
47+
}
48+
49+
type Jaeger struct {
50+
AgentHost string `yaml:"agentHost" json:"agentHost"`
51+
AgentPort int `yaml:"agentPort" json:"agentPort"`
52+
}
53+
54+
type App struct {
55+
CacheType string `yaml:"cacheType" json:"cacheType"`
56+
EnableCircuitBreaker bool `yaml:"enableCircuitBreaker" json:"enableCircuitBreaker"`
57+
EnableHTTPProfile bool `yaml:"enableHTTPProfile" json:"enableHTTPProfile"`
58+
EnableLimit bool `yaml:"enableLimit" json:"enableLimit"`
59+
EnableMetrics bool `yaml:"enableMetrics" json:"enableMetrics"`
60+
EnableStat bool `yaml:"enableStat" json:"enableStat"`
61+
EnableTrace bool `yaml:"enableTrace" json:"enableTrace"`
62+
Env string `yaml:"env" json:"env"`
63+
Host string `yaml:"host" json:"host"`
64+
Name string `yaml:"name" json:"name"`
65+
TracingSamplingRate float64 `yaml:"tracingSamplingRate" json:"tracingSamplingRate"`
66+
Version string `yaml:"version" json:"version"`
67+
}
68+
69+
type Mysql struct {
70+
ConnMaxLifetime int `yaml:"connMaxLifetime" json:"connMaxLifetime"`
71+
Dsn string `yaml:"dsn" json:"dsn"`
72+
EnableLog bool `yaml:"enableLog" json:"enableLog"`
73+
MaxIdleConns int `yaml:"maxIdleConns" json:"maxIdleConns"`
74+
MaxOpenConns int `yaml:"maxOpenConns" json:"maxOpenConns"`
75+
}
76+
77+
type Rails struct {
78+
CookieName string `yaml:"cookieName" json:"cookieName"`
79+
SecretKeyBase string `yaml:"secretKeyBase" json:"secretKeyBase"`
80+
UserID int64 `yaml:"userID" json:"userID"`
81+
}
82+
83+
type Redis struct {
84+
DialTimeout int `yaml:"dialTimeout" json:"dialTimeout"`
85+
Dsn string `yaml:"dsn" json:"dsn"`
86+
ReadTimeout int `yaml:"readTimeout" json:"readTimeout"`
87+
WriteTimeout int `yaml:"writeTimeout" json:"writeTimeout"`
88+
}
89+
90+
type Database struct {
91+
Driver string `yaml:"driver" json:"driver"`
92+
Mysql Mysql `yaml:"mysql" json:"mysql"`
93+
}
94+
95+
type JWT struct {
96+
Expire int `yaml:"expire" json:"expire"`
97+
SigningKey string `yaml:"signingKey" json:"signingKey"`
98+
}
99+
100+
type Logger struct {
101+
Format string `yaml:"format" json:"format"`
102+
IsSave bool `yaml:"isSave" json:"isSave"`
103+
Level string `yaml:"level" json:"level"`
104+
}
105+
106+
type HTTP struct {
107+
HTTPSPort int `yaml:"httpsPort" json:"httpsPort"`
108+
IdleTimeout int `yaml:"idleTimeout" json:"idleTimeout"`
109+
Port int `yaml:"port" json:"port"`
110+
ReadTimeout int `yaml:"readTimeout" json:"readTimeout"`
111+
Timeout int `yaml:"timeout" json:"timeout"`
112+
TLS TLS `yaml:"tls" json:"tls"`
113+
WriteTimeout int `yaml:"writeTimeout" json:"writeTimeout"`
114+
}
115+
116+
type Eab struct {
117+
HmacKey string `yaml:"hmacKey" json:"hmacKey"`
118+
Kid string `yaml:"kid" json:"kid"`
119+
}

0 commit comments

Comments
 (0)