chore: minor godoc refactoring

This commit is contained in:
Julien Neuhart
2023-11-19 15:02:41 +01:00
parent 5c56317d50
commit 4d1a569269
14 changed files with 51 additions and 51 deletions

View File

@@ -13,16 +13,16 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// Cmd wraps an exec.Cmd. // Cmd wraps an [exec.Cmd].
type Cmd struct { type Cmd struct {
ctx context.Context ctx context.Context
logger *zap.Logger logger *zap.Logger
process *exec.Cmd process *exec.Cmd
} }
// Command creates a Cmd without a context. It configures the internal // Command creates a [Cmd] without a context. It configures the internal
// exec.Cmd of Cmd so that we may kill its unix process and all its children // [exec.Cmd] of [Cmd] so that we may kill its unix process and all its
// without creating orphans. // children without creating orphans.
// //
// See https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773. // See https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773.
func Command(logger *zap.Logger, binPath string, args ...string) Cmd { func Command(logger *zap.Logger, binPath string, args ...string) Cmd {
@@ -36,9 +36,9 @@ func Command(logger *zap.Logger, binPath string, args ...string) Cmd {
} }
} }
// CommandContext creates a Cmd with a context. It configures the internal // CommandContext creates a [Cmd] with a context. It configures the internal
// exec.Cmd of Cmd so that we may kill its unix process and all its children // [exec.Cmd] of [Cmd] so that we may kill its unix process and all its
// without creating orphans. // children without creating orphans.
// //
// See https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773. // See https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773.
func CommandContext(ctx context.Context, logger *zap.Logger, binPath string, args ...string) (Cmd, error) { func CommandContext(ctx context.Context, logger *zap.Logger, binPath string, args ...string) (Cmd, error) {

View File

@@ -5,7 +5,7 @@ import (
"reflect" "reflect"
) )
// Context is a struct which helps initializing modules. When provisioning, a // Context is a struct which helps to initialize modules. When provisioning, a
// module may use the context to get other modules that it needs internally. // module may use the context to get other modules that it needs internally.
type Context struct { type Context struct {
flags ParsedFlags flags ParsedFlags
@@ -13,8 +13,8 @@ type Context struct {
moduleInstances map[string]interface{} moduleInstances map[string]interface{}
} }
// NewContext creates a Context. // NewContext creates a [Context].
// In a module, prefer the Provisioner interface to get a Context. // In a module, prefer the [Provisioner] interface to get a [Context].
func NewContext( func NewContext(
flags ParsedFlags, flags ParsedFlags,
descriptors []ModuleDescriptor, descriptors []ModuleDescriptor,
@@ -32,7 +32,7 @@ func NewContext(
// flags := ctx.ParsedFlags() // flags := ctx.ParsedFlags()
// m.foo = flags.RequiredString("foo") // m.foo = flags.RequiredString("foo")
// } // }
func (ctx Context) ParsedFlags() ParsedFlags { func (ctx *Context) ParsedFlags() ParsedFlags {
return ctx.flags return ctx.flags
} }
@@ -100,7 +100,7 @@ func (ctx *Context) Modules(kind interface{}) ([]interface{}, error) {
} }
// loadModule calls the Provision and/or Validate methods of the requested // loadModule calls the Provision and/or Validate methods of the requested
// module if it satisfies the Provisioner and/or Validator interfaces. // module if it satisfies the [Provisioner] and/or [Validator] interfaces.
func (ctx *Context) loadModule(id string, instance interface{}) error { func (ctx *Context) loadModule(id string, instance interface{}) error {
if prov, ok := instance.(Provisioner); ok { if prov, ok := instance.(Provisioner); ok {
// The instance can be provisioned. // The instance can be provisioned.

View File

@@ -8,7 +8,7 @@ import (
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
) )
// ParsedFlags wraps a flag.FlagSet so that retrieving the typed values is // ParsedFlags wraps a [flag.FlagSet] so that retrieving the typed values is
// easier. // easier.
type ParsedFlags struct { type ParsedFlags struct {
*flag.FlagSet *flag.FlagSet

View File

@@ -14,7 +14,7 @@ type FileSystem struct {
workingDir string workingDir string
} }
// NewFileSystem initializes a new FileSystem instance with a unique working // NewFileSystem initializes a new [FileSystem] instance with a unique working
// directory. // directory.
func NewFileSystem() *FileSystem { func NewFileSystem() *FileSystem {
return &FileSystem{ return &FileSystem{

View File

@@ -3,7 +3,7 @@ package gotenberg
import "go.uber.org/zap" import "go.uber.org/zap"
// LoggerProvider is an interface for a module that supplies a method for // LoggerProvider is an interface for a module that supplies a method for
// creating a zap.Logger instance for use by other modules. // creating a [zap.Logger] instance for use by other modules.
// //
// func (m *YourModule) Provision(ctx *gotenberg.Context) error { // func (m *YourModule) Provision(ctx *gotenberg.Context) error {
// provider, _ := ctx.Module(new(gotenberg.LoggerProvider)) // provider, _ := ctx.Module(new(gotenberg.LoggerProvider))

View File

@@ -15,7 +15,7 @@ type Metric struct {
Read func() float64 Read func() float64
} }
// MetricsProvider is a module interface which provides a list of Metric. // MetricsProvider is a module interface which provides a list of [Metric].
// //
// func (m *YourModule) Provision(ctx *gotenberg.Context) error { // func (m *YourModule) Provision(ctx *gotenberg.Context) error {
// provider, _ := ctx.Module(new(gotenberg.MetricsProvider)) // provider, _ := ctx.Module(new(gotenberg.MetricsProvider))

View File

@@ -44,12 +44,12 @@ type API struct {
srv *echo.Echo srv *echo.Echo
} }
// Router is a module interface which adds routes to the API. // Router is a module interface which adds routes to the [API].
type Router interface { type Router interface {
Routes() ([]Route, error) Routes() ([]Route, error)
} }
// Route represents a route from a Router. // Route represents a route from a [Router].
type Route struct { type Route struct {
// Method is the HTTP method of the route (i.e., GET, POST, etc.). // Method is the HTTP method of the route (i.e., GET, POST, etc.).
// Required. // Required.
@@ -72,13 +72,13 @@ type Route struct {
Handler echo.HandlerFunc Handler echo.HandlerFunc
} }
// MiddlewareProvider is a module interface which adds middlewares to the API. // MiddlewareProvider is a module interface which adds middlewares to the [API].
type MiddlewareProvider interface { type MiddlewareProvider interface {
Middlewares() ([]Middleware, error) Middlewares() ([]Middleware, error)
} }
// MiddlewareStack is a type which helps to determine in which stack the // MiddlewareStack is a type which helps to determine in which stack the
// middlewares provided by the MiddlewareProvider modules should be located. // middlewares provided by the [MiddlewareProvider] modules should be located.
type MiddlewareStack uint32 type MiddlewareStack uint32
const ( const (
@@ -88,7 +88,7 @@ const (
) )
// MiddlewarePriority is a type which helps to determine the execution order of // MiddlewarePriority is a type which helps to determine the execution order of
// middlewares provided by the MiddlewareProvider modules in a stack. // middlewares provided by the [MiddlewareProvider] modules in a stack.
type MiddlewarePriority uint32 type MiddlewarePriority uint32
const ( const (
@@ -99,7 +99,7 @@ const (
VeryHighPriority VeryHighPriority
) )
// Middleware is a middleware which can be added to the API's middlewares // Middleware is a middleware which can be added to the [API]'s middlewares
// chain. // chain.
// //
// middleware := Middleware{ // middleware := Middleware{
@@ -126,13 +126,13 @@ const (
// } // }
type Middleware struct { type Middleware struct {
// Stack tells in which stack the middleware should be located. // Stack tells in which stack the middleware should be located.
// Default to DefaultStack. // Default to [DefaultStack].
// Optional. // Optional.
Stack MiddlewareStack Stack MiddlewareStack
// Priority tells if the middleware should be positioned high or not in // Priority tells if the middleware should be positioned high or not in
// its stack. // its stack.
// Default to VeryLowPriority. // Default to [VeryLowPriority].
// Optional. // Optional.
Priority MiddlewarePriority Priority MiddlewarePriority
@@ -149,7 +149,7 @@ type HealthChecker interface {
Checks() ([]health.CheckerOption, error) Checks() ([]health.CheckerOption, error)
} }
// Descriptor returns an API's module descriptor. // Descriptor returns an [API]'s module descriptor.
func (API) Descriptor() gotenberg.ModuleDescriptor { func (API) Descriptor() gotenberg.ModuleDescriptor {
return gotenberg.ModuleDescriptor{ return gotenberg.ModuleDescriptor{
ID: "api", ID: "api",

View File

@@ -49,7 +49,7 @@ type Context struct {
context.Context context.Context
} }
// newContext returns a Context by parsing a "multipart/form-data" request. // newContext returns a [Context] by parsing a "multipart/form-data" request.
func newContext(echoCtx echo.Context, logger *zap.Logger, fs *gotenberg.FileSystem, timeout time.Duration) (*Context, context.CancelFunc, error) { func newContext(echoCtx echo.Context, logger *zap.Logger, fs *gotenberg.FileSystem, timeout time.Duration) (*Context, context.CancelFunc, error) {
processCtx, processCancel := context.WithTimeout(context.Background(), timeout) processCtx, processCancel := context.WithTimeout(context.Background(), timeout)
@@ -185,12 +185,12 @@ func newContext(echoCtx echo.Context, logger *zap.Logger, fs *gotenberg.FileSyst
return ctx, cancel, err return ctx, cancel, err
} }
// Request returns the http.Request. // Request returns the [http.Request].
func (ctx Context) Request() *http.Request { func (ctx Context) Request() *http.Request {
return ctx.echoCtx.Request() return ctx.echoCtx.Request()
} }
// FormData return a FormData. // FormData return a [FormData].
func (ctx Context) FormData() *FormData { func (ctx Context) FormData() *FormData {
return &FormData{ return &FormData{
values: ctx.values, values: ctx.values,
@@ -223,7 +223,7 @@ func (ctx *Context) AddOutputPaths(paths ...string) error {
return nil return nil
} }
// Log returns the context zap.Logger. // Log returns the context [zap.Logger].
func (ctx Context) Log() *zap.Logger { func (ctx Context) Log() *zap.Logger {
return ctx.logger return ctx.logger
} }

View File

@@ -13,7 +13,7 @@ type SentinelHTTPError struct {
message string message string
} }
// NewSentinelHTTPError creates a SentinelHTTPError. The message will be sent // NewSentinelHTTPError creates a [SentinelHTTPError]. The message will be sent
// as the response's body if returned from a handler, so make sure to not leak // as the response's body if returned from a handler, so make sure to not leak
// sensible information. // sensible information.
func NewSentinelHTTPError(status int, message string) SentinelHTTPError { func NewSentinelHTTPError(status int, message string) SentinelHTTPError {
@@ -34,7 +34,7 @@ func (err SentinelHTTPError) HTTPError() (int, string) {
} }
// sentinelWrappedError contains both the error which will logged and the // sentinelWrappedError contains both the error which will logged and the
// sidekick SentinelHTTPError. // sidekick [SentinelHTTPError].
type sentinelWrappedError struct { type sentinelWrappedError struct {
error error
sentinel SentinelHTTPError sentinel SentinelHTTPError
@@ -48,9 +48,9 @@ func (w sentinelWrappedError) HTTPError() (int, string) {
return w.sentinel.HTTPError() return w.sentinel.HTTPError()
} }
// WrapError wraps the given error with a SentinelHTTPError. The wrapped error // WrapError wraps the given error with a [SentinelHTTPError]. The wrapped
// will be displayed in a log, while the SentinelHTTPError will be sent in the // error will be displayed in a log, while the [SentinelHTTPError] will be sent
// response. // in the response.
// //
// return api.WrapError( // return api.WrapError(
// // This first error will be logged. // // This first error will be logged.

View File

@@ -23,8 +23,8 @@ type FormData struct {
errors error errors error
} }
// Validate returns nil or an error related to the FormData values, with a // Validate returns nil or an error related to the [FormData] values, with a
// SentinelHTTPError (status code 400, errors' details as message) wrapped // [SentinelHTTPError] (status code 400, errors' details as message) wrapped
// inside. // inside.
// //
// var foo string // var foo string

View File

@@ -57,8 +57,8 @@ func httpErrorHandler() echo.HTTPErrorHandler {
} }
} }
// latencyMiddleware sets the start time in the echo.Context under "startTime". // latencyMiddleware sets the start time in the [echo.Context] under
// Its value will be used later to calculate a request latency. // "startTime". Its value will be used later to calculate a request latency.
// //
// startTime := c.Get("startTime").(time.Time) // startTime := c.Get("startTime").(time.Time)
func latencyMiddleware() echo.MiddlewareFunc { func latencyMiddleware() echo.MiddlewareFunc {
@@ -74,9 +74,9 @@ func latencyMiddleware() echo.MiddlewareFunc {
} }
} }
// rootPathMiddleware sets the root path in the echo.Context under "rootPath". // rootPathMiddleware sets the root path in the [echo.Context] under
// Its value may be used to skip a middleware execution based on a request // "rootPath". Its value may be used to skip a middleware execution based on a
// URI. // request URI.
// //
// rootPath := c.Get("rootPath").(string) // rootPath := c.Get("rootPath").(string)
// healthURI := fmt.Sprintf("%s/health", rootPath) // healthURI := fmt.Sprintf("%s/health", rootPath)
@@ -97,7 +97,7 @@ func rootPathMiddleware(rootPath string) echo.MiddlewareFunc {
} }
} }
// traceMiddleware sets the request identifier in the echo.Context under // traceMiddleware sets the request identifier in the [echo.Context] under
// "trace". Its value is either retrieved from the trace header or generated if // "trace". Its value is either retrieved from the trace header or generated if
// the header is not present / its value is empty. // the header is not present / its value is empty.
// //
@@ -123,8 +123,8 @@ func traceMiddleware(header string) echo.MiddlewareFunc {
} }
} }
// loggerMiddleware sets the logger in the echo.Context under "logger" and logs // loggerMiddleware sets the logger in the [echo.Context] under "logger" and
// a synchronous request result. // logs a synchronous request result.
// //
// logger := c.Get("logger").(*zap.Logger) // logger := c.Get("logger").(*zap.Logger)
func loggerMiddleware(logger *zap.Logger, disableLoggingForPaths []string) echo.MiddlewareFunc { func loggerMiddleware(logger *zap.Logger, disableLoggingForPaths []string) echo.MiddlewareFunc {
@@ -196,9 +196,9 @@ func loggerMiddleware(logger *zap.Logger, disableLoggingForPaths []string) echo.
} }
// contextMiddleware, a middleware for "multipart/form-data" requests, sets the // contextMiddleware, a middleware for "multipart/form-data" requests, sets the
// Context and related context.CancelFunc in the echo.Context under "context" // [Context] and related context.CancelFunc in the [echo.Context] under
// and "cancel". If the process is synchronous, it also handles the result of a // "context" and "cancel". If the process is synchronous, it also handles the
// "multipart/form-data" request. // result of a "multipart/form-data" request.
// //
// ctx := c.Get("context").(*api.Context) // ctx := c.Get("context").(*api.Context)
// cancel := c.Get("cancel").(context.CancelFunc) // cancel := c.Get("cancel").(context.CancelFunc)

View File

@@ -111,8 +111,8 @@ func (c client) send(body io.Reader, headers map[string]string, erroed bool) err
return nil return nil
} }
// leveledLogger is wrapper around a zap.Logger which is used by the // leveledLogger is wrapper around a [zap.Logger] which is used by the
// retryablehttp.Client. // [retryablehttp.Client].
type leveledLogger struct { type leveledLogger struct {
logger *zap.Logger logger *zap.Logger
} }

View File

@@ -549,7 +549,7 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
}() }()
err := webhookMiddleware(tc.mod).Handler(tc.next)(c) err := webhookMiddleware(tc.mod).Handler(tc.next)(c)
if err != nil && err != api.ErrAsyncProcess { if err != nil && !errors.Is(err, api.ErrAsyncProcess) {
t.Errorf("test %d: expected no error but got: %v", i, err) t.Errorf("test %d: expected no error but got: %v", i, err)
} }

View File

@@ -30,7 +30,7 @@ type Webhook struct {
disable bool disable bool
} }
// Descriptor returns an Webhook's module descriptor. // Descriptor returns an [Webhook]'s module descriptor.
func (Webhook) Descriptor() gotenberg.ModuleDescriptor { func (Webhook) Descriptor() gotenberg.ModuleDescriptor {
return gotenberg.ModuleDescriptor{ return gotenberg.ModuleDescriptor{
ID: "webhook", ID: "webhook",