Skip to content

Commit 307b6a0

Browse files
📝 Add docstrings to wh/service-gateway
Docstrings generation was requested by @wuhan005. * #70 (comment) The following files were modified: * `internal/conf/conf.go` * `internal/route/route.go` * `route/service/proxy.go`
1 parent c131dc1 commit 307b6a0

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

internal/conf/conf.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ import (
1515
// File is the configuration object.
1616
var File *ini.File
1717

18+
// Init loads and initializes package configuration from an INI file.
19+
//
20+
// It reads NEKOBOX_CONFIG_PATH to determine the config file path (defaults to "conf/app.ini"),
21+
// parses the INI file with inline comments ignored, and maps INI sections into the package-level
22+
// configuration structs (App, Security, Server, Database, Redis, Recaptcha, Pixel, Upload, Mail).
23+
// It requires App.ExternalURL to be set and trims any trailing slash from it.
24+
//
25+
// Service child sections under the "service" section are each mapped into a backend with
26+
// `prefix` and `forward_url` fields and appended to Service.Backends.
27+
//
28+
// On success it returns nil. It returns a wrapped error if the file cannot be parsed or if any
29+
// section mapping (including individual service subsections) fails, or if App.ExternalURL is empty.
1830
func Init() error {
1931
configFile := os.Getenv("NEKOBOX_CONFIG_PATH")
2032
if configFile == "" {
@@ -84,4 +96,4 @@ func Init() error {
8496
}
8597

8698
return nil
87-
}
99+
}

internal/route/route.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import (
3535
"github.com/wuhan005/NekoBox/templates"
3636
)
3737

38+
// New creates and returns a fully configured Flamego application.
39+
//
40+
// The returned instance is configured with environment mode (production when enabled), embedded HTML templates, session storage (memory, MySQL, or Redis depending on configuration), static file serving, route groups and handlers (including web and API endpoints), common middleware (cache, reCAPTCHA v3, session, CSRF, templating, and custom context), and a NotFound handler that redirects to "/".
3841
func New() *flamego.Flame {
3942
f := flamego.Classic()
4043
if conf.App.Production {
@@ -183,4 +186,4 @@ func New() *flamego.Flame {
183186
})
184187

185188
return f
186-
}
189+
}

route/service/proxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
"github.com/wuhan005/NekoBox/internal/context"
1919
)
2020

21+
// Proxy forwards the incoming request to a configured backend based on the request path,
22+
// propagates tracing headers and the authenticated user ID, and writes the proxied response back to the client.
23+
// It returns an error when the request could not be proxied and an HTTP error response was written
24+
// (for example when no backend matches or when the backend URL is invalid); otherwise it returns nil.
2125
func Proxy(ctx context.Context) error {
2226
span := trace.SpanFromContext(ctx.Request().Context())
2327

@@ -81,4 +85,4 @@ func Proxy(ctx context.Context) error {
8185

8286
reverseProxy.ServeHTTP(ctx.ResponseWriter(), ctx.Request().Request)
8387
return nil
84-
}
88+
}

0 commit comments

Comments
 (0)