rename 'internal/config' to 'internal/api' | rename 'internal.api.Load()' to 'internal.api.Parse()'
This commit is contained in:
parent
fd6d7b661e
commit
7bcbefdf35
|
@ -1,4 +1,4 @@
|
||||||
package config
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load builds a representation of the configuration
|
// Parse builds a representation of the configuration
|
||||||
// The struct definition checks for most format errors
|
// The struct definition checks for most format errors
|
||||||
//
|
//
|
||||||
// path<string> The path to the configuration
|
// path<string> The path to the configuration
|
||||||
|
@ -15,7 +15,7 @@ import (
|
||||||
// @return<controller> The parsed configuration root controller
|
// @return<controller> The parsed configuration root controller
|
||||||
// @return<err> The error if occurred
|
// @return<err> The error if occurred
|
||||||
//
|
//
|
||||||
func Load(path string) (*Controller, error) {
|
func Parse(path string) (*Controller, error) {
|
||||||
|
|
||||||
/* (1) Extract data
|
/* (1) Extract data
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
|
@ -1,4 +1,4 @@
|
||||||
package config
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.xdrm.io/go/aicra/middleware"
|
"git.xdrm.io/go/aicra/middleware"
|
|
@ -1,4 +1,4 @@
|
||||||
package config
|
package api
|
||||||
|
|
||||||
/* (1) Configuration
|
/* (1) Configuration
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
10
server.go
10
server.go
|
@ -3,8 +3,8 @@ package aicra
|
||||||
import (
|
import (
|
||||||
"git.xdrm.io/go/aicra/driver"
|
"git.xdrm.io/go/aicra/driver"
|
||||||
e "git.xdrm.io/go/aicra/err"
|
e "git.xdrm.io/go/aicra/err"
|
||||||
|
"git.xdrm.io/go/aicra/internal/api"
|
||||||
"git.xdrm.io/go/aicra/internal/checker"
|
"git.xdrm.io/go/aicra/internal/checker"
|
||||||
"git.xdrm.io/go/aicra/internal/config"
|
|
||||||
apirequest "git.xdrm.io/go/aicra/internal/request"
|
apirequest "git.xdrm.io/go/aicra/internal/request"
|
||||||
"git.xdrm.io/go/aicra/middleware"
|
"git.xdrm.io/go/aicra/middleware"
|
||||||
"log"
|
"log"
|
||||||
|
@ -14,9 +14,9 @@ import (
|
||||||
// Server represents an AICRA instance featuring:
|
// Server represents an AICRA instance featuring:
|
||||||
// * its type checkers
|
// * its type checkers
|
||||||
// * its middlewares
|
// * its middlewares
|
||||||
// * its controllers (config)
|
// * its controllers (api config)
|
||||||
type Server struct {
|
type Server struct {
|
||||||
controller *config.Controller // controllers
|
controller *api.Controller // controllers
|
||||||
checker *checker.Registry // type checker registry
|
checker *checker.Registry // type checker registry
|
||||||
middleware *middleware.Registry // middlewares
|
middleware *middleware.Registry // middlewares
|
||||||
driver driver.Driver
|
driver driver.Driver
|
||||||
|
@ -50,7 +50,7 @@ func New(_path string, _driver driver.Driver) (*Server, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (2) Load configuration */
|
/* (2) Load configuration */
|
||||||
i.controller, err = config.Load(_path)
|
i.controller, err = api.Parse(_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
// extractParameters extracts parameters for the request and checks
|
// extractParameters extracts parameters for the request and checks
|
||||||
// every single one according to configuration options
|
// every single one according to configuration options
|
||||||
func (s *Server) extractParameters(req *apirequest.Request, methodParam map[string]*config.Parameter) (map[string]interface{}, e.Error) {
|
func (s *Server) extractParameters(req *apirequest.Request, methodParam map[string]*api.Parameter) (map[string]interface{}, e.Error) {
|
||||||
|
|
||||||
// init vars
|
// init vars
|
||||||
err := e.Success
|
err := e.Success
|
||||||
|
|
4
util.go
4
util.go
|
@ -3,14 +3,14 @@ package aicra
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.xdrm.io/go/aicra/err"
|
"git.xdrm.io/go/aicra/err"
|
||||||
"git.xdrm.io/go/aicra/internal/config"
|
"git.xdrm.io/go/aicra/internal/api"
|
||||||
apirequest "git.xdrm.io/go/aicra/internal/request"
|
apirequest "git.xdrm.io/go/aicra/internal/request"
|
||||||
"git.xdrm.io/go/aicra/response"
|
"git.xdrm.io/go/aicra/response"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) matchController(req *apirequest.Request) *config.Controller {
|
func (s *Server) matchController(req *apirequest.Request) *api.Controller {
|
||||||
|
|
||||||
/* (1) Try to browse by URI */
|
/* (1) Try to browse by URI */
|
||||||
pathi, ctl := s.controller.Browse(req.URI)
|
pathi, ctl := s.controller.Browse(req.URI)
|
||||||
|
|
Loading…
Reference in New Issue