added initial swagger docs.
This commit is contained in:
117
cmd/paste/config.go
Normal file
117
cmd/paste/config.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/docopt/docopt.go"
|
||||
"github.com/spf13/viper"
|
||||
"sour.is/x/toolbox/httpsrv"
|
||||
"sour.is/x/toolbox/log"
|
||||
)
|
||||
|
||||
var (
|
||||
// AppVersion Application Version Number
|
||||
AppVersion string
|
||||
|
||||
// AppBuild Application Build Number
|
||||
AppBuild string
|
||||
)
|
||||
|
||||
// AppName name of the application
|
||||
var AppName = "Paste API"
|
||||
|
||||
// AppUsage displays runtime options
|
||||
var AppUsage = `Paste API
|
||||
|
||||
Usage:
|
||||
paste version
|
||||
paste [ -v | -vv ] serve
|
||||
|
||||
Options:
|
||||
-v Log info to console.
|
||||
-vv Log debug to console.
|
||||
-l <ListenAddress>, --listen=<ListenAddress> Address to listen on.
|
||||
-c <ConfigDir>, --config=<ConfigDir> Set Config Directory.
|
||||
|
||||
Config:
|
||||
The config file is read from the following locations:
|
||||
- <ConfigDir>
|
||||
- /etc/opt/sour.is/paste/
|
||||
- Working Directory
|
||||
`
|
||||
var defaultConfig = `
|
||||
[http]
|
||||
listen = ":9010"
|
||||
|
||||
[module.paste]
|
||||
random = "4096"
|
||||
store = "data/"
|
||||
`
|
||||
|
||||
var args map[string]interface{}
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
if args, err = docopt.Parse(AppUsage, nil, true, AppVersion, false); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if args["-v"].(int) == 1 {
|
||||
log.SetVerbose(log.Vinfo)
|
||||
}
|
||||
if args["-v"].(int) == 2 {
|
||||
log.SetVerbose(log.Vdebug)
|
||||
log.Debug("Debug Logging.")
|
||||
}
|
||||
|
||||
viper.SetConfigName("config")
|
||||
if args["--config"] != nil {
|
||||
viper.AddConfigPath(args["--config"].(string))
|
||||
}
|
||||
|
||||
viper.AddConfigPath("/etc/opt/sour.is/paste/")
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
viper.SetConfigType("toml")
|
||||
viper.ReadConfig(bytes.NewBuffer([]byte(defaultConfig)))
|
||||
|
||||
err = viper.MergeInConfig()
|
||||
if err != nil { // Handle errors reading the config file
|
||||
log.Fatalf("Fatal error config file: %s \n", err)
|
||||
}
|
||||
|
||||
viper.Set("app.name", AppName)
|
||||
|
||||
viper.SetDefault("app.version", "VERSION")
|
||||
if AppVersion != "" {
|
||||
viper.Set("app.version", AppVersion)
|
||||
}
|
||||
|
||||
viper.SetDefault("app.build", "SNAPSHOT")
|
||||
if AppBuild != "" {
|
||||
viper.Set("app.build", AppBuild)
|
||||
}
|
||||
|
||||
if args["serve"] == true {
|
||||
|
||||
if args["--listen"] != nil {
|
||||
viper.Set("http.listen", args["--listen"].(string))
|
||||
}
|
||||
|
||||
log.Noticef("Startup: %s (%s %s)",
|
||||
viper.GetString("app.name"),
|
||||
viper.GetString("app.version"),
|
||||
viper.GetString("app.build"))
|
||||
|
||||
log.Notice("Read config from: ", viper.ConfigFileUsed())
|
||||
httpsrv.Config()
|
||||
|
||||
} else if args["version"] == true {
|
||||
fmt.Printf("Version: %s (%s %s)\n",
|
||||
viper.GetString("app.name"),
|
||||
viper.GetString("app.version"),
|
||||
viper.GetString("app.build"))
|
||||
}
|
||||
}
|
||||
41
cmd/paste/main.go
Normal file
41
cmd/paste/main.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Package Paste API.
|
||||
//
|
||||
// the purpose of this application is to provide an application
|
||||
// that is using plain go code to define an API
|
||||
//
|
||||
// Terms Of Service:
|
||||
//
|
||||
// there are no TOS at this moment, use at your own risk we take no responsibility
|
||||
//
|
||||
// Schemes: http, https
|
||||
// Host: paste.sour.is
|
||||
// BasePath: /
|
||||
// Version: 0.0.1
|
||||
// License: MIT http://opensource.org/licenses/MIT
|
||||
// Contact: Xuu <me@sour.is> https://sour.is
|
||||
//
|
||||
// Consumes:
|
||||
// - application/json
|
||||
// - text/plain
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
// - text/plain
|
||||
//
|
||||
//
|
||||
// swagger:meta
|
||||
package main // import "sour.is/x/paste/cmd/paste"
|
||||
|
||||
import (
|
||||
"sour.is/x/toolbox/httpsrv"
|
||||
_ "sour.is/x/paste/src/routes"
|
||||
_ "sour.is/x/paste/src/docs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if args["serve"] == true {
|
||||
httpsrv.Run()
|
||||
}
|
||||
}
|
||||
|
||||
//go:generate swagger generate spec -o ../../src/docs/public/swagger.json
|
||||
Reference in New Issue
Block a user