代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"os"
"runtime"
"rttys/config"
"rttys/utils"
"rttys/version"
xlog "rttys/log"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
func initDb(cfg *config.Config) error {
db, err := instanceDB(cfg.DB)
if err != nil {
return err
}
defer db.Close()
_, err = db.Exec("CREATE TABLE IF NOT EXISTS config(name VARCHAR(512) PRIMARY KEY NOT NULL, value TEXT NOT NULL)")
if err != nil {
return err
}
_, err = db.Exec("CREATE TABLE IF NOT EXISTS account(username VARCHAR(512) PRIMARY KEY NOT NULL, password TEXT NOT NULL, admin INT NOT NULL)")
if err != nil {
return err
}
_, err = db.Exec("CREATE TABLE IF NOT EXISTS device(id VARCHAR(512) PRIMARY KEY NOT NULL, description TEXT NOT NULL, online DATETIME NOT NULL, username TEXT NOT NULL)")
return err
}
func runRttys(c *cli.Context) error {
xlog.SetPath(c.String("log"))
if c.Bool("verbose") {
xlog.Verbose()
}
cfg, err := config.Parse(c)
if err != nil {
return err
}
log.Info().Msg("Go Version: " + runtime.Version())
log.Info().Msgf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
log.Info().Msg("Rttys Version: " + version.Version())
gitCommit := version.GitCommit()
buildTime := version.BuildTime()
if gitCommit != "" {
log.Info().Msg("Git Commit: " + version.GitCommit())
}
if buildTime != "" {
log.Info().Msg("Build Time: " + version.BuildTime())
}
err = initDb(cfg)
if err != nil {
return fmt.Errorf(`init database: %s`, err.Error())
}
br := newBroker(cfg)
go br.run()
listenDevice(br)
listenHttpProxy(br)
apiStart(br)
select {}
}
func main() {
defaultLogPath := "/var/log/rttys.log"
if runtime.GOOS == "windows" {
defaultLogPath = "rttys.log"
}
app := &cli.App{
Name: "rttys",
Usage: "The server side for rtty",
Version: version.Version(),
Commands: []*cli.Command{
{
Name: "run",
Usage: "Run rttys",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "log",
Value: defaultLogPath,
Usage: "log file path",
},
&cli.StringFlag{
Name: "conf",
Aliases: []string{"c"},
Usage: "config file to load",
},
&cli.StringFlag{
Name: "addr-dev",
Value: ":5912",
Usage: "address to listen device",
},
&cli.StringFlag{
Name: "addr-user",
Value: ":5913",
Usage: "address to listen user",
},
&cli.StringFlag{
Name: "addr-http-proxy",
Usage: "address to listen for HTTP proxy (default auto)",
},
&cli.StringFlag{
Name: "http-proxy-redir-url",
Usage: "url to redirect for HTTP proxy",
},
&cli.StringFlag{
Name: "http-proxy-redir-domain",
Usage: "domain for HTTP proxy set cookie",
},
&cli.StringFlag{
Name: "ssl-cert",
Usage: "ssl cert file Path",
},
&cli.StringFlag{
Name: "ssl-key",
Usage: "ssl key file Path",
},
&cli.StringFlag{
Name: "ssl-cacert",
Usage: "mtls CA storage in PEM file Path",
},
&cli.StringFlag{
Name: "token",
Aliases: []string{"t"},
Usage: "token to use",
},
&cli.StringFlag{
Name: "dev-auth-url",
Usage: "using device auth url instead of token",
},
&cli.StringFlag{
Name: "white-list",
Usage: "white list(device IDs separated by spaces or *)",
},
&cli.StringFlag{
Name: "db",
Value: "sqlite://rttys.db",
Usage: "database source",
},
&cli.BoolFlag{
Name: "local-auth",
Value: true,
Usage: "need auth for local",
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"V"},
Usage: "more detailed output",
},
},
Action: func(c *cli.Context) error {
return runRttys(c)
},
},
{
Name: "token",
Usage: "Generate a token",
Action: func(c *cli.Context) error {
utils.GenToken()
return nil
},
},
},
Action: func(c *cli.Context) error {
return c.App.Command("run").Run(c)
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。