apimain

package
v0.0.0-...-381b1be Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 12 Imported by: 1

README

apimain

-- import "github.com/dockerian/go-coding/api"

Package apimain :: app.go - main api entrance

Package apimain :: appEnv.go

Package apimain :: appRouters.go

Package apimain :: appServer.go

Package apimain :: info.go

Package apimain :: root.go

Usage

var (
	// ListenPort is a configurable http port
	ListenPort = 8181

	// RootRoutes configures root routes
	// optionally read from config or move this to routes.go
	RootRoutes = Routes{
		{
			"/", "GET", rootHandler, "Index",
		},
		{
			"/info", "GET", GetInfo, "Info",
		},
	}
)
func App
func App()

App is the API main entrance

func AppIndex
func AppIndex(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

AppIndex handles the root of api path

func GetConfig
func GetConfig() *cfg.Config

GetConfig returns an application configuration

func GetDbInfo
func GetDbInfo(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

GetDbInfo handles /info/db path

func GetDbInfoAll
func GetDbInfoAll(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

GetDbInfoAll handles /info/db/all path

func GetInfo
func GetInfo(res http.ResponseWriter, req *http.Request)

GetInfo is api/info handler

func Index
func Index(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

Index handles the root of api path

func Info
func Info(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

Info handles /info path

func ListenAndServe
func ListenAndServe(server api.AppServerInterface, ctx *cfg.Context) error

ListenAndServe starts a server

func NewAppContext
func NewAppContext() *cfg.Context

NewAppContext constructs an cfg.Context for the application

func NewAppEnv
func NewAppEnv() *cfg.Env

NewAppEnv constructs an cfg.Env for the application

func NewAppServer
func NewAppServer() *api.AppServer

NewAppServer constructs AppServer with

- a new `*mux.Router`
- negroni middlewares

Any middleware by negroni.Use() should implement negroni.Handler interface:

```
ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
```

otherwise, by negroni.UseHandler() should implements http.Handler.

see https://github.com/urfave/negroni#handlers

func NotDefined
func NotDefined(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

NotDefined handles any unimplemented path

func NotFound
func NotFound(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

NotFound handles /{rest} path

func Root
func Root()

Root is api root entry pointer

type APIInfo
type APIInfo struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"desc,omitempty"`
	Copyright   string `json:"copyright,omitempty"`
	Author      string `json:"author,omitempty"`
	APIURL      string `json:"api_url,omitempty"`
	APIInfoURL  string `json:"api_info_url,omitempty"`
	APIVersion  string `json:"api_version,omitempty"`
	Version     string `json:"version,omitempty"`
}

APIInfo struct

type Route
type Route struct {
	Pattern string
	Method  string
	Handler http.HandlerFunc
	Name    string
}

Route struct encapsulates an http route

type Routes
type Routes []Route

Routes struct is an array of Route

Documentation

Overview

Package apimain :: app.go - main api entrance

Package apimain :: appEnv.go

Package apimain :: appRouters.go

Package apimain :: appServer.go

Package apimain :: info.go

Package apimain :: root.go

Index

Constants

This section is empty.

Variables

View Source
var (
	// ListenPort is a configurable http port
	ListenPort = 8181

	// RootRoutes configures root routes
	// optionally read from config or move this to routes.go
	RootRoutes = Routes{
		{
			"/", "GET", rootHandler, "Index",
		},
		{
			"/info", "GET", GetInfo, "Info",
		},
	}
)

Functions

func App

func App()

App is the API main entrance

func AppIndex

func AppIndex(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

AppIndex handles the root of api path

func GetConfig

func GetConfig() *cfg.Config

GetConfig returns an application configuration

func GetDbInfo

func GetDbInfo(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

GetDbInfo handles /info/db path

func GetDbInfoAll

func GetDbInfoAll(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

GetDbInfoAll handles /info/db/all path

func GetInfo

func GetInfo(res http.ResponseWriter, req *http.Request)

GetInfo is api/info handler

func Index

func Index(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

Index handles the root of api path

func Info

func Info(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

Info handles /info path

func ListenAndServe

func ListenAndServe(server api.AppServerInterface, ctx *cfg.Context) error

ListenAndServe starts a server

func NewAppContext

func NewAppContext() *cfg.Context

NewAppContext constructs an cfg.Context for the application

func NewAppEnv

func NewAppEnv() *cfg.Env

NewAppEnv constructs an cfg.Env for the application

func NewAppServer

func NewAppServer() *api.AppServer

NewAppServer constructs AppServer with

  • a new `*mux.Router`
  • negroni middlewares

Any middleware by `negroni.Use()` should implement `negroni.Handler` interface:

```
ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
```

otherwise, by `negroni.UseHandler()` should implements `http.Handler`.

see https://github.com/urfave/negroni#handlers

func NotDefined

func NotDefined(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

NotDefined handles any unimplemented path

func NotFound

func NotFound(ctx cfg.Context, w http.ResponseWriter, r *http.Request) error

NotFound handles /{rest} path

func Root

func Root()

Root is api root entry pointer

Types

type APIInfo

type APIInfo struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"desc,omitempty"`
	Copyright   string `json:"copyright,omitempty"`
	Author      string `json:"author,omitempty"`
	APIURL      string `json:"api_url,omitempty"`
	APIInfoURL  string `json:"api_info_url,omitempty"`
	APIVersion  string `json:"api_version,omitempty"`
	Version     string `json:"version,omitempty"`
}

APIInfo struct

type Route

type Route struct {
	Pattern string
	Method  string
	Handler http.HandlerFunc
	Name    string
}

Route struct encapsulates an http route

type Routes

type Routes []Route

Routes struct is an array of Route

Directories

Path Synopsis
Package db :: db.go - MySql database functions
Package db :: db.go - MySql database functions
v1
client
Package client :: items__.go - Query result items
Package client :: items__.go - Query result items

Jump to

Keyboard shortcuts

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