mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:54:03 +03:00
Working version
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
|
||||
"github.com/9seconds/mtg/server"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -43,7 +47,8 @@ var (
|
||||
func main() {
|
||||
kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||
|
||||
if matched, err := regexp.MatchString("[a-fA-F0-9]+", *secret); !matched || err != nil {
|
||||
secretBytes, err := hex.DecodeString(*secret)
|
||||
if err != nil {
|
||||
usage("Secret has to be hexadecimal string.")
|
||||
}
|
||||
|
||||
@@ -61,8 +66,23 @@ func main() {
|
||||
*serverName = strings.TrimSpace(string(myIPBytes))
|
||||
}
|
||||
|
||||
atom := zap.NewAtomicLevel()
|
||||
if *debug {
|
||||
atom.SetLevel(zapcore.DebugLevel)
|
||||
} else {
|
||||
atom.SetLevel(zapcore.ErrorLevel)
|
||||
}
|
||||
encoderCfg := zap.NewProductionEncoderConfig()
|
||||
logger := zap.New(zapcore.NewCore(
|
||||
zapcore.NewJSONEncoder(encoderCfg),
|
||||
zapcore.Lock(os.Stderr),
|
||||
atom,
|
||||
)).Sugar()
|
||||
|
||||
printURLs()
|
||||
serve()
|
||||
if err := server.NewServer(*bindIP, int(*bindPort), secretBytes, logger).Serve(); err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func usage(msg string) {
|
||||
@@ -88,7 +108,3 @@ func printURLs() {
|
||||
tgURL.Path = "proxy"
|
||||
fmt.Println(tgURL.String())
|
||||
}
|
||||
|
||||
func serve() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user