Skip to content

Commit 0babfcb

Browse files
committed
✨Please port thruster "Automatic TLS certificate management with Let's Encrypt" to current user_server-web-http project, you can read thruster source code from /Users/guochunzhong/git/oss/thruster, no need do remote clone from https://github.com/basecamp/thruster.
Below is thruster's Automatic TLS function location, as a hint and maybe not complete: - HTTP(S) servers: [internal/server.go](mdc:internal/server.go) - HTTP always listens on `HTTP_PORT`; if TLS is configured, HTTP only redirects to HTTPS - HTTPS listens on `HTTPS_PORT` with autocert from `ACME_DIRECTORY` and optional EAB - Timeouts come from config: idle/read/write - TLS decisions: [internal/config.go](mdc:internal/config.go) - `HasTLS()` is true when `TLS_DOMAIN` has one or more domains - Certificates cached under `STORAGE_PATH` Please remember using configs/user_server.yml style configure instead of ENV style. If you need change sponge, the direct dependency of user_server-web-http, do it at `/Users/guochunzhong/git/oss/sponge` directly.
1 parent a0221f4 commit 0babfcb

File tree

8 files changed

+368
-141
lines changed

8 files changed

+368
-141
lines changed

cmd/user_server/initial/createService.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package initial
22

33
import (
4-
"strconv"
5-
64
"test-user-server/internal/config"
75
"test-user-server/internal/server"
86

@@ -15,8 +13,7 @@ func CreateServices() []app.IServer {
1513
var servers []app.IServer
1614

1715
// create a http service
18-
httpAddr := ":" + strconv.Itoa(cfg.HTTP.Port)
19-
httpServer := server.NewHTTPServer(httpAddr,
16+
httpServer := server.NewHTTPServer(cfg.HTTP,
2017
server.WithHTTPIsProd(cfg.App.Env == "prod"),
2118
)
2219
servers = append(servers, httpServer)

configs/user_server.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ app:
2020
# http server settings
2121
http:
2222
port: 8080 # listen port
23+
httpsPort: 8443 # https listen port when tls is enabled
2324
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+
idleTimeout: 60 # http idle timeout, unit(second)
26+
readTimeout: 30 # http read timeout, unit(second)
27+
writeTimeout: 30 # http write timeout, unit(second)
28+
tls:
29+
domains:
30+
- "" # list of domains for automatic tls certificates, empty disables tls
31+
acmeDirectory: "https://acme-v02.api.letsencrypt.org/directory" # acme directory url
32+
storagePath: "./storage/autocert" # directory to cache certificates
33+
eab:
34+
kid: "" # external account binding key identifier
35+
hmacKey: "" # base64url encoded external account binding hmac key
2436

2537

2638

@@ -83,5 +95,3 @@ jaeger:
8395
agentPort: 6831
8496

8597

86-
87-

deployments/kubernetes/user_server-configmap.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ data:
2727
# http server settings
2828
http:
2929
port: 8080 # listen port
30+
httpsPort: 8443 # https listen port when tls is enabled
3031
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
32+
idleTimeout: 60 # http idle timeout, unit(second)
33+
readTimeout: 30 # http read timeout, unit(second)
34+
writeTimeout: 30 # http write timeout, unit(second)
35+
tls:
36+
domains:
37+
- "" # list of domains for automatic tls certificates, empty disables tls
38+
acmeDirectory: "https://acme-v02.api.letsencrypt.org/directory" # acme directory url
39+
storagePath: "./storage/autocert" # directory to cache certificates
40+
eab:
41+
kid: "" # external account binding key identifier
42+
hmacKey: "" # base64url encoded external account binding hmac key
3143
3244
3345

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
1111
github.com/swaggo/gin-swagger v1.5.2
1212
github.com/swaggo/swag v1.8.12
13+
golang.org/x/crypto v0.36.0
1314
golang.org/x/sync v0.12.0
1415
gorm.io/gorm v1.30.3
1516
)
@@ -110,7 +111,6 @@ require (
110111
go.uber.org/multierr v1.9.0 // indirect
111112
go.uber.org/zap v1.24.0 // indirect
112113
golang.org/x/arch v0.8.0 // indirect
113-
golang.org/x/crypto v0.36.0 // indirect
114114
golang.org/x/net v0.38.0 // indirect
115115
golang.org/x/sys v0.34.0 // indirect
116116
golang.org/x/text v0.23.0 // indirect

internal/config/user_server.go

Lines changed: 49 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)