Changeset 55 in code for trunk/cmd/simplytranslate


Ignore:
Timestamp:
Jan 19, 2024, 10:49:09 AM (17 months ago)
Author:
yakumo.izuru
Message:

「swagger」サポートを削除し、あちこちのバグを修正

Location:
trunk/cmd/simplytranslate
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/simplytranslate/main.go

    r53 r55  
    66        "net/url"
    77        "time"
    8         "flag"
     8        "runtime"
    99
    1010        "git.chaotic.ninja/yakumo.izuru/simplytranslate/engines"
    1111        "github.com/gofiber/fiber/v2"
    1212        "github.com/gofiber/template/html/v2"
    13         "gopkg.in/ini.v1"
    1413)
    1514
     
    1918        tmplpath string
    2019}
    21 func readConf(file string) error {
    22         cfg, err := ini.Load(file)
    23         if err != nil {
    24                 return err
    25         }
    26         conf.listen = cfg.Section("").Key("listen").String()
    27         conf.staticpath = cfg.Section("").Key("rootdir").String()
    28         conf.tmplpath = cfg.Section("").Key("tmplpath").String()
    29 
    30         return nil
    31 }
    3220func main() {
    33         var configfile string
    34         flag.StringVar(&configfile, "f", "", "Configuration file")
    35         flag.Parse()
     21        parseFlags()
    3622
    3723        if configfile != "" {
     
    3925        }
    4026
     27        // Default settings
    4128        conf.listen = "127.0.0.1:5000"
    4229        conf.staticpath = "./static"
     
    4936                Views: engine,
    5037        })
     38
     39        api := app.Group("/api")
    5140
    5241        app.All("/", func(c *fiber.Ctx) error {
     
    149138        })
    150139
    151         app.All("/api/translate", func(c *fiber.Ctx) error {
     140        api.All("/api/translate", func(c *fiber.Ctx) error {
    152141                from := ""
    153142                to := ""
     
    180169        })
    181170
    182         app.Get("/api/source_languages", func(c *fiber.Ctx) error {
     171        api.Get("/api/source_languages", func(c *fiber.Ctx) error {
    183172                engine := c.Query("engine")
    184173                if _, ok := engines.Engines[engine]; !ok || engine == "" {
     
    192181        })
    193182
    194         app.Get("/api/target_languages", func(c *fiber.Ctx) error {
     183        api.Get("/api/target_languages", func(c *fiber.Ctx) error {
    195184                engine := c.Query("engine")
    196185                if _, ok := engines.Engines[engine]; !ok || engine == "" {
     
    204193        })
    205194
    206         app.Get("/api/tts", func(c *fiber.Ctx) error {
     195        api.Get("/api/tts", func(c *fiber.Ctx) error {
    207196                engine := c.Query("engine")
    208197                if _, ok := engines.Engines[engine]; !ok || engine == "" {
     
    231220                }
    232221        })
    233 
     222        api.Get("/version", func(c *fiber.Ctx) error {
     223                return c.JSON(fiber.Map{
     224                        "fiberversion": fiber.Version,
     225                        "goversion": runtime.Version(),
     226                })
     227        })
    234228        app.Post("/switchlanguages", func(c *fiber.Ctx) error {
    235229                if c.Cookies("from") != "" {
Note: See TracChangeset for help on using the changeset viewer.