You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
5.3 KiB

/* ——————————————————————————————————————————————————————————————————————————
Proyecto goat
—————————————————————————————————————————————————————————————————————————————
Fichero a.go
Package errs
Autor Juan V. Navarro juanvnl@activething.com
Creado 03/02/2026
—————————————————————————————————————————————————————————————————————————————
LICENSES AND TERMS OF USE
-------------------------
This software is licensed under the Elastic License v2.0 (the "License").
For full terms and additional information regarding permitted and prohibited
uses, please visit:
https://activething.com/ATGO/licenses
You may use, copy, modify, and redistribute this software internally within
your organization for any purpose, including research, development, and
testing, subject to the terms of this License.
You may NOT, however, use, provide, distribute, or make this software
available to any third party as part of a hosted service, SaaS offering, or
commercial product without first obtaining a commercial license from
Active Thing.
You may combine this software with other code, provided that such
combination does not circumvent the restrictions of this License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. In no event shall
the authors or copyright holders be liable for any claim, damages, or other
liability arising from the use of this software.
—————————————————————————————————————————————————————————————————————————————
Web : activething.com | activething.com/goat
git : g.activething.com | github.com/activething/goat
Correo : dev@activething.com
—————————————————————————————————————————————————————————————————————————————
No deseo caminar sobre el agua", dijo Siddhartha.
Que los antiguos chamanes se contenten con tales habilidades.
—— Hermann Hesse, Siddhartha
—————————————————————————————————————————————————————————————————————————————
Copyright (c) 2026 Active Thing
————————————————————————————————————————————————————————————————————————————— */
package errs
const (
// ModSys para errores de infraestructura y sistema operativo.
ModSys = Module("sys")
// ModSrv para errores de comunicación entre servicios y red.
ModSrv = Module("srv")
// ModApp para la lógica de negocio principal.
ModApp = Module("app")
)
const (
// ModuleName define el namespace reservado para los errores de este propio paquete.
ModuleName = Module("errs")
// ErrInvalidModule indica que el código no tiene un formato de módulo válido
// (ej. falta "::" o el nombre del módulo tiene caracteres prohibidos).
ErrInvalidModule = Code(ModuleName + ModuleSep + "invalid_module_name")
ErrRegisteredModule = Code(ModuleName + ModuleSep + "module_already_registered")
// ErrInvalidCode indica un error genérico en la estructura del código
// (ej. uso de "::" doble, segmentos vacíos).
ErrInvalidCode = Code(ModuleName + ModuleSep + "invalid_error_code")
// ErrInvalidCodeLen indica que el código no alcanza la longitud mínima requerida
// para contener un módulo y un error (min: "a::b").
ErrInvalidCodeLen = Code(string(ErrInvalidModule) + string(CodeSep) + "invalid_len")
// ErrInvalidCodeChar indica el uso de caracteres prohibidos (mayúsculas, símbolos)
// o una disposición ilegal de separadores (ej. terminar en '.').
ErrInvalidCodeChar = Code(string(ErrInvalidModule) + string(CodeSep) + "invalid_char")
)
var (
registry = make(map[string]struct{})
)
// MustRegisterModule Es el constructor estándar para definir módulos globales.
// Panica si:
// 1. El nombre es inválido (caracteres no permitidos).
// 2. El módulo ya ha sido registrado previamente en la aplicación.
func MustRegisterModule(name string) Module {
if !isValidSegment(name, minModuleSeg) {
panic(ErrInvalidModule)
}
if _, ok := registry[name]; ok {
panic(ErrRegisteredModule)
}
registry[name] = struct{}{}
return Module(name)
}
// RegisteredModules devuelve los nombres de todos los módulos activos.
// Útil para debugging o endpoints de inspección.
func RegisteredModules() []string {
list := make([]string, 0, len(registry))
for name := range registry {
list = append(list, name)
}
return list
}

Powered by TurnKey Linux.