conf

package
v0.0.0-...-aa14b41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_HTTP_PORT           = "port"
	KEY_DYNAMIC_ROUTE       = "dynamic_route"
	KEY_HTTP_ROOT           = "db_root"
	KEY_CONSUL_API_BASE     = "consul_api_base"
	KEY_CONSUL_SERVICE_NAME = "consul_service_name"
	KEY_CONSUL_SERVICE_HOST = "consul_service_host"

	DEFAULT_HTTP_PORT    = 8080
	DEFAULT_DYNAMIC_POST = true
	DEFAULT_HTTP_ROOT    = "http-server-root"

	CONTENT_TYPE_CHARSET  = "charset="
	CONTENT_TYPE_BOUNDARY = "boundary="

	MIME_TYPE_JSON = "application/json"
	MIME_TYPE_YAML = "application/yaml"

	DEFAULT_FILE_EXT = ".json"
)

Variables

View Source
var (
	HTTP_METHOD_GET    = enum.InitEnum[HTTP_METHOD]("GET", "GET")
	HTTP_METHOD_POST   = enum.InitEnum[HTTP_METHOD]("POST", "POST")
	HTTP_METHOD_PUT    = enum.InitEnum[HTTP_METHOD]("PUT", "PUT")
	HTTP_METHOD_DELETE = enum.InitEnum[HTTP_METHOD]("DELETE", "DELETE")

	HTTP_ACTION_APPEND = enum.InitEnum[HTTP_ACTION]("a", "append")
	HTTP_ACTION_READ   = enum.InitEnum[HTTP_ACTION]("r", "read")
	HTTP_ACTION_WRITE  = enum.InitEnum[HTTP_ACTION]("w", "write")
	HTTP_ACTION_DELETE = enum.InitEnum[HTTP_ACTION]("d", "delete")

	DEFAULT_RESPONSE = map[string]bool{"success": true}

	FILE_EXT_JSON = []string{"json"}
	FILE_EXT_YAML = []string{"yaml", "yml"}

	JsonResolver = JsonFileResolver{}
	YamlResolver = YamlFileResolver{}

	MimeTypeMap = make(map[string]HttpFileType)
	FileExtMap  = make(map[string]HttpFileType)
)

Functions

func FileExists

func FileExists(file string) bool

func ParseAndRun

func ParseAndRun()

Types

type ClientConfig

type ClientConfig interface {
	Start()
}

type HTTP_ACTION

type HTTP_ACTION enum.Enum

type HTTP_METHOD

type HTTP_METHOD enum.Enum

type HttpFileModel

type HttpFileModel struct {
	PostResponse map[string]any `json:"post_response,omitempty"`
	DelResponse  map[string]any `json:"del_response,omitempty"`
	Datum        map[string]any `json:"datum,omitempty"`
	Data         []any          `json:"data,omitempty"`
}

type HttpFileResolver

type HttpFileResolver interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(data []byte, v any) error
	ContentType() string
}

type HttpFileType

type HttpFileType struct {
	MimeType       string
	FileExts       []string
	DefaultFileExt string
	Resolver       HttpFileResolver
}

type HttpServer

type HttpServer struct {
	Port              int16
	DynamicRoute      bool
	DBRoot            string
	ConsulApiBase     string
	ConsulServiceName string
	ConsulServiceHost string
	StaticRoutes      RouteMap
}

func (*HttpServer) Listen

func (server *HttpServer) Listen()

func (*HttpServer) ServeHTTP

func (server *HttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type JsonFileResolver

type JsonFileResolver struct{}

func (JsonFileResolver) ContentType

func (resolver JsonFileResolver) ContentType() string

func (JsonFileResolver) Marshal

func (resolver JsonFileResolver) Marshal(v any) ([]byte, error)

func (JsonFileResolver) Unmarshal

func (resolver JsonFileResolver) Unmarshal(data []byte, v any) error

type Route

type Route struct {
	Path          string
	Method        *HTTP_METHOD
	Action        *HTTP_ACTION
	File          string
	Single        bool
	Id            []string
	Fields        []string
	UniqueNotList bool
	Resolver      HttpFileResolver
}

func (Route) ServAppend

func (route Route) ServAppend(w http.ResponseWriter, r *http.Request, values url.Values)

func (Route) ServDelete

func (route Route) ServDelete(w http.ResponseWriter, r *http.Request, values url.Values)

func (Route) ServHTTP

func (route Route) ServHTTP(w http.ResponseWriter, r *http.Request, values url.Values)

func (Route) ServRead

func (route Route) ServRead(w http.ResponseWriter, r *http.Request, values url.Values)

func (Route) ServWrite

func (route Route) ServWrite(w http.ResponseWriter, r *http.Request, values url.Values)

func (Route) WriteResponse

func (route Route) WriteResponse(w http.ResponseWriter, data any) bool

type RouteInfo

type RouteInfo struct {
	Path          string   `toml:"path,omitempty"`
	Method        string   `toml:"method,omitempty"`
	Action        string   `toml:"action,omitempty"`
	Format        string   `toml:"format,omitempty"`
	File          string   `toml:"file,omitempty"`
	Single        bool     `toml:"single,omitempty"`
	Id            []string `toml:"id,omitempty"`
	Fields        []string `toml:"fields,omitempty"`
	UniqueNotList bool     `toml:"unique_not_list,omitempty"`
}

type RouteInfoMap

type RouteInfoMap map[string]RouteInfo

type RouteMap

type RouteMap map[string]Route

type ServerConfig

type ServerConfig interface {
	Listen()
}

type YamlFileResolver

type YamlFileResolver struct{}

func (YamlFileResolver) ContentType

func (resolver YamlFileResolver) ContentType() string

func (YamlFileResolver) Marshal

func (resolver YamlFileResolver) Marshal(v any) ([]byte, error)

func (YamlFileResolver) Unmarshal

func (resolver YamlFileResolver) Unmarshal(data []byte, v any) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL