「swagger」サポートを削除し、あちこちのバグを修正
git-svn-id: file:///srv/svn/repo/mai/trunk@55 e410bdd4-646f-c54f-a7ce-fffcc4f439ae
This commit is contained in:
12
cmd/simplytranslate/flag.go
Normal file
12
cmd/simplytranslate/flag.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// Set up a basic command line flags parsing
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
)
|
||||
|
||||
func parseFlags() {
|
||||
var configfile string
|
||||
flag.StringVar(&configfile, "f", "", "Configuration file")
|
||||
flag.Parse()
|
||||
}
|
||||
@@ -5,12 +5,11 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
"flag"
|
||||
"runtime"
|
||||
|
||||
"git.chaotic.ninja/yakumo.izuru/simplytranslate/engines"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/template/html/v2"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
var conf struct {
|
||||
@@ -18,26 +17,14 @@ var conf struct {
|
||||
staticpath string
|
||||
tmplpath string
|
||||
}
|
||||
func readConf(file string) error {
|
||||
cfg, err := ini.Load(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conf.listen = cfg.Section("").Key("listen").String()
|
||||
conf.staticpath = cfg.Section("").Key("rootdir").String()
|
||||
conf.tmplpath = cfg.Section("").Key("tmplpath").String()
|
||||
|
||||
return nil
|
||||
}
|
||||
func main() {
|
||||
var configfile string
|
||||
flag.StringVar(&configfile, "f", "", "Configuration file")
|
||||
flag.Parse()
|
||||
parseFlags()
|
||||
|
||||
if configfile != "" {
|
||||
readConf(configfile)
|
||||
}
|
||||
|
||||
// Default settings
|
||||
conf.listen = "127.0.0.1:5000"
|
||||
conf.staticpath = "./static"
|
||||
conf.tmplpath = "./views"
|
||||
@@ -49,6 +36,8 @@ func main() {
|
||||
Views: engine,
|
||||
})
|
||||
|
||||
api := app.Group("/api")
|
||||
|
||||
app.All("/", func(c *fiber.Ctx) error {
|
||||
engine := c.Cookies("engine")
|
||||
if c.Query("engine") != "" {
|
||||
@@ -148,7 +137,7 @@ func main() {
|
||||
})
|
||||
})
|
||||
|
||||
app.All("/api/translate", func(c *fiber.Ctx) error {
|
||||
api.All("/api/translate", func(c *fiber.Ctx) error {
|
||||
from := ""
|
||||
to := ""
|
||||
engine := ""
|
||||
@@ -179,7 +168,7 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
app.Get("/api/source_languages", func(c *fiber.Ctx) error {
|
||||
api.Get("/api/source_languages", func(c *fiber.Ctx) error {
|
||||
engine := c.Query("engine")
|
||||
if _, ok := engines.Engines[engine]; !ok || engine == "" {
|
||||
engine = "google"
|
||||
@@ -191,7 +180,7 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
app.Get("/api/target_languages", func(c *fiber.Ctx) error {
|
||||
api.Get("/api/target_languages", func(c *fiber.Ctx) error {
|
||||
engine := c.Query("engine")
|
||||
if _, ok := engines.Engines[engine]; !ok || engine == "" {
|
||||
engine = "google"
|
||||
@@ -203,7 +192,7 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
app.Get("/api/tts", func(c *fiber.Ctx) error {
|
||||
api.Get("/api/tts", func(c *fiber.Ctx) error {
|
||||
engine := c.Query("engine")
|
||||
if _, ok := engines.Engines[engine]; !ok || engine == "" {
|
||||
engine = "google"
|
||||
@@ -230,7 +219,12 @@ func main() {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
api.Get("/version", func(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{
|
||||
"fiberversion": fiber.Version,
|
||||
"goversion": runtime.Version(),
|
||||
})
|
||||
})
|
||||
app.Post("/switchlanguages", func(c *fiber.Ctx) error {
|
||||
if c.Cookies("from") != "" {
|
||||
fromCookie := new(fiber.Cookie)
|
||||
|
||||
20
cmd/simplytranslate/readconf.go
Normal file
20
cmd/simplytranslate/readconf.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// Read the INI-style configuration file
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
func readConf(file string) error {
|
||||
cfg, err := ini.Load(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.listen = cfg.Section("simplytranslate").Key("listen").String()
|
||||
conf.staticpath = cfg.Section("simplytranslate").Key("rootdir").String()
|
||||
conf.tmplpath = cfg.Section("simplytranslate").Key("tmplpath").String()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user