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.
100 lines
4.8 KiB
100 lines
4.8 KiB
/* ——————————————————————————————————————————————————————————————————————————
|
|
Proyecto goat
|
|
—————————————————————————————————————————————————————————————————————————————
|
|
Fichero module.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 (
|
|
moduleSepChar = ':'
|
|
ModuleSep = "::"
|
|
lenModuleSep = 2
|
|
minModuleSeg = 1
|
|
)
|
|
|
|
// Module representa un espacio de nombres (namespace) único y normalizado.
|
|
//
|
|
// Un módulo actúa como la raíz de una jerarquía de errores. Su propósito es
|
|
// garantizar que todos los códigos generados bajo su ámbito compartan un
|
|
// origen común, facilitando la trazabilidad y el filtrado en logs y métricas.
|
|
//
|
|
// Reglas de Valor:
|
|
// - Debe ser un nombre "puro" (ej. "database", no "database::").
|
|
// - Solo admite minúsculas [a-z], números [0-9] y guiones bajos '_'.
|
|
// - Se recomienda que sea corto, descriptivo y representativo de un
|
|
// componente o subsistema.
|
|
|
|
type Module string
|
|
|
|
// MakeModule crea un nuevo espacio de nombres para errores.
|
|
// Solo acepta nombres "puros" (ej. "auth", no "auth::").
|
|
// Si el nombre contiene caracteres no permitidos o el separador '::', lanza un pánico.
|
|
func MakeModule(name string) Module {
|
|
// Validamos que el nombre sea un segmento válido (minúsculas, números, _)
|
|
// y que cumpla la longitud mínima para módulos (ej. 1 o 2 caracteres)
|
|
if !isValidSegment(name, minModuleSeg) {
|
|
panic(ErrInvalidModule)
|
|
}
|
|
return Module(name)
|
|
}
|
|
|
|
// MakeCode genera un Code perteneciente a este módulo.
|
|
// Ejemplo: authMod.MakeCode("user_not_found") -> "auth::user_not_found"
|
|
func (m Module) MakeCode(code string) Code {
|
|
if !isValidSegment(code, minCodeSeg) {
|
|
panic(ErrInvalidCode)
|
|
}
|
|
return Code(string(m) + ModuleSep + code)
|
|
}
|
|
|
|
func ValidateModule(module string) error {
|
|
if !isValidSegment(module, minModuleSeg) {
|
|
return ErrInvalidModule
|
|
}
|
|
return nil
|
|
}
|