fix: semantic renaming : internal.config.Method.Permission is now Scope

This commit is contained in:
Adrien Marquès 2019-05-02 20:57:58 +02:00
parent 189d3b40a6
commit eb5ce4c0d0
4 changed files with 41 additions and 4 deletions

28
internal/cerr/cerr.go Normal file
View File

@ -0,0 +1,28 @@
package cerr
// Error allows you to create constant "const" error with type boxing.
type Error string
// Error implements the error builtin interface.
func (err Error) Error() string {
return string(err)
}
// Wrap returns a new error which wraps a new error into itself.
func (err Error) Wrap(e error) *WrapError {
return &WrapError{
base: err,
wrap: e,
}
}
// WrapError is way to wrap errors recursively.
type WrapError struct {
base error
wrap error
}
// Error implements the error builtin interface recursively.
func (err *WrapError) Error() string {
return err.base.Error() + ": " + err.wrap.Error()
}

View File

@ -26,7 +26,7 @@ type Parameter struct {
// Method represents a method definition (from api.json)
type Method struct {
Description string `json:"info"`
Permission [][]string `json:"scope"`
Scope [][]string `json:"scope"`
Parameters map[string]*Parameter `json:"in"`
Download *bool `json:"download"`
}

View File

@ -6,8 +6,16 @@ import (
"io"
"net/http"
"strings"
"git.xdrm.io/go/aicra/internal/cerr"
)
// ErrReadConfig - a problem ocurred when trying to read the configuration file
const ErrReadConfig = cerr.Error("cannot read config")
// ErrFormatConfig - a invalid format has been detected
const ErrFormatConfig = cerr.Error("invalid config format")
// Parse builds a service from a json reader and checks for most format errors.
func Parse(r io.Reader) (*Service, error) {
@ -15,12 +23,13 @@ func Parse(r io.Reader) (*Service, error) {
err := json.NewDecoder(r).Decode(receiver)
if err != nil {
return nil, err
return nil, ErrReadConfig.Wrap(err)
}
ErrFormatConfig.Wrap(fmt.Errorf("blable"))
err = receiver.checkAndFormat("/")
if err != nil {
return nil, err
return nil, ErrFormatConfig.Wrap(err)
}
return receiver, nil

View File

@ -132,7 +132,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
/* (6) Execute handler and return response
---------------------------------------------------------*/
// 1. feed request with configuration scope
request.Scope = methodDef.Permission
request.Scope = methodDef.Scope
// 1. execute
response := api.NewResponse()