github.com/wanliu/go-oauth2-server@v0.0.0-20180817021415-f928fa1580df/go_oauth2_server.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	"github.com/urfave/cli"
     8  	"github.com/wanliu/go-oauth2-server/cmd"
     9  )
    10  
    11  var (
    12  	cliApp        *cli.App
    13  	configBackend string
    14  )
    15  
    16  func init() {
    17  	// Initialise a CLI app
    18  	cliApp = cli.NewApp()
    19  	cliApp.Name = "wanliu-oauth2-server"
    20  	cliApp.Usage = "Wanliu OAuth 2.0 Server"
    21  	cliApp.Author = "Hysios Hu"
    22  	cliApp.Email = "hysios@gmail.com"
    23  	cliApp.Version = "0.0.0"
    24  	cliApp.Flags = []cli.Flag{
    25  		cli.StringFlag{
    26  			Name:        "configBackend",
    27  			Value:       "etcd",
    28  			Destination: &configBackend,
    29  		},
    30  	}
    31  }
    32  
    33  func main() {
    34  	// Set the CLI app commands
    35  	cliApp.Commands = []cli.Command{
    36  		{
    37  			Name:  "migrate",
    38  			Usage: "run migrations",
    39  			Action: func(c *cli.Context) error {
    40  				return cmd.Migrate(configBackend)
    41  			},
    42  		},
    43  		{
    44  			Name:  "loaddata",
    45  			Usage: "load data from fixture",
    46  			Action: func(c *cli.Context) error {
    47  				return cmd.LoadData(c.Args(), configBackend)
    48  			},
    49  		},
    50  		{
    51  			Name:  "runserver",
    52  			Usage: "run web server",
    53  			Action: func(c *cli.Context) error {
    54  				return cmd.RunServer(configBackend)
    55  			},
    56  		},
    57  		{
    58  			Name:  "setup",
    59  			Usage: "setup oauth server",
    60  			Action: func(c *cli.Context) error {
    61  				return cmd.Setup(configBackend)
    62  			},
    63  		},
    64  	}
    65  
    66  	// Run the CLI app
    67  	if err := cliApp.Run(os.Args); err != nil {
    68  		log.Fatal(err)
    69  	}
    70  }