goapp

package module
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 11 Imported by: 3

README

goapp Build Status GoDoc License

The package is used to initialize an application to simply the creation. Support Go1.13+.

Install

$ go get -u github.com/xgfone/goapp

Usage

package main

import (
	"github.com/xgfone/gconf/v6"
	"github.com/xgfone/go-log"
	"github.com/xgfone/go-log/logf"
	"github.com/xgfone/goapp"
	"github.com/xgfone/goapp/http/ship/router"
	"github.com/xgfone/ship/v5"
)

var opts = []gconf.Opt{
	gconf.StrOpt("opt1", "help doc"),
	gconf.IntOpt("opt2", "help doc"),
}

func main() {
	addr := gconf.NewString("addr", ":80", "The address to listen to.")
	goapp.Init("app", opts...)

	// Initialize the app router.
	app := router.InitRouter(nil)
	app.Logger = logf.NewLogger(log.DefaultLogger, 0)
	app.Route("/path1").GET(ship.OkHandler())
	app.Route("/path2").GET(func(c *ship.Context) error { return c.Text(200, "OK") })

	// Start the HTTP server.
	router.StartServer(addr.Get(), app)
}

Build the application above by Makefile like this,

$ make
$ go run main.go --help
  --addr string
        The address to listen to. (default: ":80")
  --config-file string
        the config file path. (default: "")
  --log.file string
        The file path of the log. The default is stdout. (default: "")
  --log.level string
        The level of the log, such as debug, info, etc. (default: "info")
  --opt1 string
        help doc (default: "")
  --opt2 int
        help doc (default: "0")
  --version bool
        Print the version and exit. (default: "false")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallInit added in v0.21.0

func CallInit() (err error)

CallInit calls the registered initialization functions.

func Init added in v0.7.0

func Init(appName string, opts ...gconf.Opt)

Init is used to initialize the application.

  1. Register the log options.
  2. Initialize configuration.
  3. Initialize the logging.
  4. Call the registered initialization functions.

func RegisterInit added in v0.21.0

func RegisterInit(initfuncs ...func() error)

RegisterInit registers the initialization functions.

Types

This section is empty.

Directories

Path Synopsis
Package config is used to configure the application.
Package config is used to configure the application.
Package db provides some assistant functions about the database.
Package db provides some assistant functions about the database.
Package exec provides some convenient execution functions.
Package exec provides some convenient execution functions.
http
httpserver
Package httpserver provides some http server functions.
Package httpserver provides some http server functions.
ship/router
Package router suppies some router assistant functions, such as the router Handlers and Middlewares.
Package router suppies some router assistant functions, such as the router Handlers and Middlewares.
Package log is used to initialize the logging.
Package log is used to initialize the logging.
Package redis provides some assistant functions about redis.
Package redis provides some assistant functions about redis.
Package remote provides the command execution functions on the remote host.
Package remote provides the command execution functions on the remote host.
Package validate supplies a struct validator to validate whether the field value of the struct is valid or not.
Package validate supplies a struct validator to validate whether the field value of the struct is valid or not.

Jump to

Keyboard shortcuts

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