unexport aicra errors
This commit is contained in:
parent
e0ea0c97c5
commit
5cadfcf78b
10
builder.go
10
builder.go
|
@ -29,7 +29,7 @@ func (b *Builder) AddType(t datatype.T) {
|
||||||
b.conf = &config.Server{}
|
b.conf = &config.Server{}
|
||||||
}
|
}
|
||||||
if b.conf.Services != nil {
|
if b.conf.Services != nil {
|
||||||
panic(ErrLateType)
|
panic(errLateType)
|
||||||
}
|
}
|
||||||
b.conf.Types = append(b.conf.Types, t)
|
b.conf.Types = append(b.conf.Types, t)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func (b *Builder) Setup(r io.Reader) error {
|
||||||
b.conf = &config.Server{}
|
b.conf = &config.Server{}
|
||||||
}
|
}
|
||||||
if b.conf.Services != nil {
|
if b.conf.Services != nil {
|
||||||
panic(ErrAlreadySetup)
|
panic(errAlreadySetup)
|
||||||
}
|
}
|
||||||
return b.conf.Parse(r)
|
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
|
// Bind a dynamic handler to a REST service
|
||||||
func (b *Builder) Bind(method, path string, fn interface{}) error {
|
func (b *Builder) Bind(method, path string, fn interface{}) error {
|
||||||
if b.conf.Services == nil {
|
if b.conf.Services == nil {
|
||||||
return ErrNotSetup
|
return errNotSetup
|
||||||
}
|
}
|
||||||
|
|
||||||
// find associated service
|
// find associated service
|
||||||
|
@ -62,7 +62,7 @@ func (b *Builder) Bind(method, path string, fn interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if service == nil {
|
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)
|
dyn, err := dynfunc.Build(fn, *service)
|
||||||
|
@ -91,7 +91,7 @@ func (b Builder) Build() (http.Handler, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !hasAssociatedHandler {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
errors.go
21
errors.go
|
@ -3,22 +3,21 @@ package aicra
|
||||||
// cerr allows you to create constant "const" error with type boxing.
|
// cerr allows you to create constant "const" error with type boxing.
|
||||||
type cerr string
|
type cerr string
|
||||||
|
|
||||||
// Error implements the error builtin interface.
|
|
||||||
func (err cerr) Error() string {
|
func (err cerr) Error() string {
|
||||||
return string(err)
|
return string(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrLateType - cannot add datatype after setting up the definition
|
// errLateType - cannot add datatype after setting up the definition
|
||||||
const ErrLateType = cerr("types cannot be added after Setup")
|
const errLateType = cerr("types cannot be added after Setup")
|
||||||
|
|
||||||
// ErrNotSetup - not set up yet
|
// errNotSetup - not set up yet
|
||||||
const ErrNotSetup = cerr("not set up")
|
const errNotSetup = cerr("not set up")
|
||||||
|
|
||||||
// ErrAlreadySetup - already set up
|
// errAlreadySetup - already set up
|
||||||
const ErrAlreadySetup = cerr("already set up")
|
const errAlreadySetup = cerr("already set up")
|
||||||
|
|
||||||
// ErrUnknownService - no service matching this handler
|
// errUnknownService - no service matching this handler
|
||||||
const ErrUnknownService = cerr("unknown service")
|
const errUnknownService = cerr("unknown service")
|
||||||
|
|
||||||
// ErrMissingHandler - missing handler
|
// errMissingHandler - missing handler
|
||||||
const ErrMissingHandler = cerr("missing handler")
|
const errMissingHandler = cerr("missing handler")
|
||||||
|
|
Loading…
Reference in New Issue