Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/main.go
Chris MacLeod c9b72206a5 Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds

The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.

* Style changes and old code removal in router

Router needs a lot of work done to its (lack of) error handling.

* Dead code removal and style changes

Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.

* Finish dead code removal and style changes

Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.

* Fix accidental find-and-replace

* Style, error checking, saftey, bug fix changes

* Redo error checking erased during merge

* Re-add merge-erased fix. Make Safe safe.
2017-05-09 21:34:40 -05:00

86 lignes
1,7 Kio
Go

package main
import (
"bufio"
"flag"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/network"
"github.com/ewhal/nyaa/router"
"github.com/ewhal/nyaa/util/log"
"github.com/ewhal/nyaa/util/signals"
"net/http"
"os"
"path/filepath"
"time"
)
func initI18N() {
/* Initialize the languages translation */
i18n.MustLoadTranslationFile("translations/en-us.all.json")
paths, err := filepath.Glob("translations/*.json")
if err == nil {
for _, path := range paths {
i18n.LoadTranslationFile(path)
}
}
}
func RunServer(conf *config.Config) {
http.Handle("/", router.Router)
// Set up server,
srv := &http.Server{
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
l, err := network.CreateHTTPListener(conf)
log.CheckError(err)
if err == nil {
log.Infof("listening on %s", l.Addr())
err := srv.Serve(l)
log.CheckError(err)
}
}
func main() {
conf := config.New()
processFlags := conf.BindFlags()
defaults := flag.Bool("print-defaults", false, "print the default configuration file on stdout")
flag.Parse()
if *defaults {
stdout := bufio.NewWriter(os.Stdout)
err := conf.Pretty(stdout)
if err != nil {
log.Fatal(err.Error())
}
err = stdout.Flush()
if err != nil {
log.Fatal(err.Error())
}
os.Exit(0)
} else {
err := processFlags()
if err != nil {
log.CheckError(err)
}
db.ORM, err = db.GormInit(conf)
if err != nil {
log.Fatal(err.Error())
}
initI18N()
go signals.Handle()
if len(config.TorrentFileStorage) > 0 {
err := os.MkdirAll(config.TorrentFileStorage, 0700)
if err != nil {
log.Fatal(err.Error())
}
}
RunServer(conf)
}
}