unexport aicra errors

This commit is contained in:
Adrien Marquès 2020-04-04 12:40:21 +02:00
parent e0ea0c97c5
commit 5cadfcf78b
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
2 changed files with 15 additions and 16 deletions

View File

@ -29,7 +29,7 @@ func (b *Builder) AddType(t datatype.T) {
b.conf = &config.Server{}
}
if b.conf.Services != nil {
panic(ErrLateType)
panic(errLateType)
}
b.conf.Types = append(b.conf.Types, t)
}
@ -41,7 +41,7 @@ func (b *Builder) Setup(r io.Reader) error {
b.conf = &config.Server{}
}
if b.conf.Services != nil {
panic(ErrAlreadySetup)
panic(errAlreadySetup)
}
return b.conf.Parse(r)
}
@ -49,7 +49,7 @@ func (b *Builder) Setup(r io.Reader) error {
// Bind a dynamic handler to a REST service
func (b *Builder) Bind(method, path string, fn interface{}) error {
if b.conf.Services == nil {
return ErrNotSetup
return errNotSetup
}
// find associated service
@ -62,7 +62,7 @@ func (b *Builder) Bind(method, path string, fn interface{}) error {
}
if service == nil {
return fmt.Errorf("%s '%s': %w", method, path, ErrUnknownService)
return fmt.Errorf("%s '%s': %w", method, path, errUnknownService)
}
dyn, err := dynfunc.Build(fn, *service)
@ -91,7 +91,7 @@ func (b Builder) Build() (http.Handler, error) {
}
}
if !hasAssociatedHandler {
return nil, fmt.Errorf("%s '%s': %w", service.Method, service.Pattern, ErrMissingHandler)
return nil, fmt.Errorf("%s '%s': %w", service.Method, service.Pattern, errMissingHandler)
}
}

View File

@ -3,22 +3,21 @@ package aicra
// cerr allows you to create constant "const" error with type boxing.
type cerr string
// Error implements the error builtin interface.
func (err cerr) Error() string {
return string(err)
}
// ErrLateType - cannot add datatype after setting up the definition
const ErrLateType = cerr("types cannot be added after Setup")
// errLateType - cannot add datatype after setting up the definition
const errLateType = cerr("types cannot be added after Setup")
// ErrNotSetup - not set up yet
const ErrNotSetup = cerr("not set up")
// errNotSetup - not set up yet
const errNotSetup = cerr("not set up")
// ErrAlreadySetup - already set up
const ErrAlreadySetup = cerr("already set up")
// errAlreadySetup - already set up
const errAlreadySetup = cerr("already set up")
// ErrUnknownService - no service matching this handler
const ErrUnknownService = cerr("unknown service")
// errUnknownService - no service matching this handler
const errUnknownService = cerr("unknown service")
// ErrMissingHandler - missing handler
const ErrMissingHandler = cerr("missing handler")
// errMissingHandler - missing handler
const errMissingHandler = cerr("missing handler")