moved 'config' in /internal

This commit is contained in:
Adrien Marquès 2018-05-20 10:46:39 +02:00
parent 7f8910f793
commit c9326a1bb3
2 changed files with 15 additions and 14 deletions

View File

@ -1,14 +1,14 @@
package gfw package config
import ( import (
"encoding/json" "encoding/json"
"os" "os"
) )
// LoadConfig builds a structured representation of the // Load builds a structured representation of the
// configuration file located at @path // configuration file located at @path
// The struct definition checks for most format errors // The struct definition checks for most format errors
func LoadConfig(path string) (*controller, error) { func Load(path string) (*Controller, error) {
/* (1) Extract data /* (1) Extract data
---------------------------------------------------------*/ ---------------------------------------------------------*/
@ -20,7 +20,7 @@ func LoadConfig(path string) (*controller, error) {
defer configFile.Close() defer configFile.Close()
/* (2) Init receiving dataset */ /* (2) Init receiving dataset */
receiver := &controller{} receiver := &Controller{}
/* (3) Decode JSON */ /* (3) Decode JSON */
decoder := json.NewDecoder(configFile) decoder := json.NewDecoder(configFile)
@ -30,4 +30,5 @@ func LoadConfig(path string) (*controller, error) {
} }
return receiver, nil return receiver, nil
} }

View File

@ -1,27 +1,27 @@
package gfw package config
/* (1) Configuration /* (1) Configuration
---------------------------------------------------------*/ ---------------------------------------------------------*/
type methodParameter struct { type MethodParameter struct {
Description string `json:"des"` Description string `json:"des"`
Type string `json:"typ"` Type string `json:"typ"`
Rename *string `json:"ren"` Rename *string `json:"ren"`
Optional *bool `json:"opt"` Optional *bool `json:"opt"`
Default *interface{} `json:"def"` Default *interface{} `json:"def"`
} }
type method struct { type Method struct {
Description string `json:"des"` Description string `json:"des"`
Permission [][]string `json:"per"` Permission [][]string `json:"per"`
Parameters *map[string]methodParameter `json:"par"` Parameters *map[string]MethodParameter `json:"par"`
Options *map[string]interface{} `json:"opt"` Options *map[string]interface{} `json:"opt"`
} }
type controller struct { type Controller struct {
GET *method `json:"GET"` GET *Method `json:"GET"`
POST *method `json:"POST"` POST *Method `json:"POST"`
PUT *method `json:"PUT"` PUT *Method `json:"PUT"`
DELETE *method `json:"DELETE"` DELETE *Method `json:"DELETE"`
Children map[string]controller `json:"/"` Children map[string]Controller `json:"/"`
} }