Documentation
¶
Overview ¶
Package codex provides a generator for generating error code related implementations.
How to Integrate Generator ¶
import _ "github.com/xoctopus/genx/devpkg/codex"
ctx := genx.NewContext(&genx.Args{
Entrypoint: []string{entry},
})
_ = ctx.Execute(context.Background(), genx.Get("code")...)
Code Definition Conventions ¶
- Add `// +genx:code` on the error code type.
- Define constants with `<PREFIX>_UNDEFINED` and `<PREFIX>__<NAME>` (see genx skill generator-codex.spec.md).
- Optional HTTP mapping: on each constant doc, `// @code api=StatusBadRequest` or `// @code api=http=444`. Invalid api values log a warning and omit that constant from StatusCode(). Unannotated codes map to StatusCode() 0; types with no api omit StatusCode().
Domain in Message() ¶
Default domain is UPPER(package)::UPPER(TypeName). Optional type doc override: `// @code domain=MYDOMAIN`. Constant docs use only `api` for HTTP, not domain.
Example:
// +genx:code type Code int8 const ( CODE_UNDEFINED Code = iota // CODE__ERROR1 error1 message // @code api=StatusBadRequest CODE__ERROR1 )
Example ¶
cwd := must.NoErrorV(os.Getwd())
entry := filepath.Join(cwd, "..", "testdata", "codex")
ctx := genx.NewContext(&genx.Args{
Entrypoint: []string{entry},
})
must.NoError(ctx.Execute(context.Background(), genx.Get()...))
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveStatusAnnoValue ¶ added in v0.4.0
ResolveStatusAnnoValue resolves annotation of api eg:
@code api=StatusInternalServerError @code api=http=500
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func (*Error) CodeMessageCases ¶
CodeMessageCases generates code snippet for error message cases
type HTTPStatusRegistry ¶ added in v0.4.0
type HTTPStatusRegistry struct {
// contains filtered or unexported fields
}
HTTPStatusRegistry maps net/http status constant names (StatusOK) to numeric codes. Populated once from go/types so we stay aligned with the toolchain's net/http.
func (HTTPStatusRegistry) StatusCodeOf ¶ added in v0.4.0
func (r HTTPStatusRegistry) StatusCodeOf(name string) (int, bool)
Click to show internal directories.
Click to hide internal directories.