rename 'internal/api' to 'internal/apidef' (api definition)

This commit is contained in:
Adrien Marquès 2018-10-07 11:40:35 +02:00
parent f157785cff
commit 0eee615aea
5 changed files with 14 additions and 14 deletions

View File

@ -1,4 +1,4 @@
package api package apidef
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package api package apidef
import ( import (
"git.xdrm.io/go/aicra/middleware" "git.xdrm.io/go/aicra/middleware"

View File

@ -1,4 +1,4 @@
package api package apidef
/* (1) Configuration /* (1) Configuration
---------------------------------------------------------*/ ---------------------------------------------------------*/

View File

@ -2,14 +2,14 @@ package aicra
import ( import (
"errors" "errors"
"git.xdrm.io/go/aicra/api"
"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/apidef"
"git.xdrm.io/go/aicra/internal/checker" "git.xdrm.io/go/aicra/internal/checker"
"git.xdrm.io/go/aicra/internal/config" "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"
"git.xdrm.io/go/aicra/response"
"log" "log"
"net/http" "net/http"
"path/filepath" "path/filepath"
@ -21,7 +21,7 @@ import (
// * its middlewares // * its middlewares
// * its controllers (api config) // * its controllers (api config)
type Server struct { type Server struct {
controller *api.Controller // controllers controller *apidef.Controller // controllers
checker checker.Registry // type checker registry checker checker.Registry // type checker registry
middleware middleware.Registry // middlewares middleware middleware.Registry // middlewares
schema *config.Schema schema *config.Schema
@ -46,7 +46,7 @@ func New(_path string) (*Server, error) {
} }
/* 3. Load configuration */ /* 3. Load configuration */
i.controller, err = api.Parse(_path) i.controller, err = apidef.Parse(_path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -166,7 +166,7 @@ func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) {
return return
} }
var ctlMethod func(response.Arguments) response.Response var ctlMethod func(api.Arguments) api.Response
// select method // select method
switch httpMethod { switch httpMethod {
case "GET": case "GET":
@ -214,7 +214,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]*api.Parameter) (map[string]interface{}, e.Error) { func (s *Server) extractParameters(req *apirequest.Request, methodParam map[string]*apidef.Parameter) (map[string]interface{}, e.Error) {
// init vars // init vars
err := e.Success err := e.Success

10
util.go
View File

@ -2,15 +2,15 @@ package aicra
import ( import (
"encoding/json" "encoding/json"
"git.xdrm.io/go/aicra/api"
"git.xdrm.io/go/aicra/err" "git.xdrm.io/go/aicra/err"
"git.xdrm.io/go/aicra/internal/api" "git.xdrm.io/go/aicra/internal/apidef"
apirequest "git.xdrm.io/go/aicra/internal/request" apireq "git.xdrm.io/go/aicra/internal/request"
"git.xdrm.io/go/aicra/response"
"log" "log"
"net/http" "net/http"
) )
func (s *Server) matchController(req *apirequest.Request) *api.Controller { func (s *Server) matchController(req *apireq.Request) *apidef.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)
@ -34,7 +34,7 @@ func httpRedirect(r http.ResponseWriter, loc string) {
} }
// Prints an HTTP response // Prints an HTTP response
func httpPrint(r http.ResponseWriter, res response.Response) { func httpPrint(r http.ResponseWriter, res api.Response) {
// get response data // get response data
formattedResponse := res.Dump() formattedResponse := res.Dump()