goapp

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

README

goapp Build Status GoDoc License

The package is used to initialize an application to simply the creation.

Install

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

Usage

package main

import (
	"github.com/xgfone/gconf/v5"
	"github.com/xgfone/gconf/v5/field"
	"github.com/xgfone/goapp"
	"github.com/xgfone/goapp/router"
	"github.com/xgfone/ship/v3"
)

// Define some options.
var (
	conf config
	opts = []gconf.Opt{
		gconf.StrOpt("opt1", "help doc"),
		gconf.IntOpt("opt2", "help doc"),
	}
)

type config struct {
	Addr field.StringOptField `default:":80" help:"The address to listen to."`
}

func main() {
	// Initialize the app configuration
	goapp.Init("app", &conf, opts)

	// Initialize and start the app router.
	app := router.InitRouter()
	app.Route("/path1").GET(ship.OkHandler())
	app.Route("/path2").GET(func(c *ship.Context) error { return c.Text(200, "OK") })
	app.Start(conf.Addr.Get()).Wait()
}

Build the application above by using the script build.sh like this,

$ ./build.sh
$ ./app --help
  --addr string
        The address to listen to. (default ":80")
  --config-file string
        the config file path.
  --logfile string
        The file path of the log. The default is stdout.
  --loglevel string
        The level of the log, such as debug, info (default "info")
  --opt1 string
        help doc
  --opt2 int
        help doc
  --version bool
        Print the version and exit.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppRouter = router.App

AppRouter is the default app router.

Functions

func Init added in v0.7.0

func Init(appName string, configOptions ...interface{})

Init is equal to InitApp(appName, gover.Text(), configOptions...).

func InitApp

func InitApp(appName, version string, options ...interface{})

InitApp initializes the application, which is equal to

InitApp2(appName, version, "100M", 100, options...)

func InitApp2 added in v0.4.0

func InitApp2(appName, version, logfilesize string, logfilenum int, options ...interface{})

InitApp2 initializes the application.

  1. Register the log options.
  2. Initialize configuration.
  3. Initialize the logging.

func Unix

func Unix(sec, nsec int64) time.Time

Unix returns a time with unixstamp in UTC location.

Types

This section is empty.

Directories

Path Synopsis
Package config is used to initialize the configuration.
Package config is used to initialize the configuration.
Package db supplies some assistant functions about the database.
Package db supplies some assistant functions about the database.
Package log is used to initialize the logger, and supplies some assistant functions about log.
Package log is used to initialize the logger, and supplies some assistant functions about log.
Package net supplies some assistant functions about net, such as the gateway ip and routes.
Package net supplies some assistant functions about net, such as the gateway ip and routes.
Package opentracing is used to initialize the opentracing from the plugin, and supplies the OpenTracing http.RoundTripper and router middleware.
Package opentracing is used to initialize the opentracing from the plugin, and supplies the OpenTracing http.RoundTripper and router middleware.
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 scanner is the replacer of the stdlib `bufio.Scanner`, which adds the read offset.
Package scanner is the replacer of the stdlib `bufio.Scanner`, which adds the read offset.
Package slice supplies some assistant functions about slice.
Package slice supplies some assistant functions about slice.

Jump to

Keyboard shortcuts

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