代码拉取完成,页面将自动刷新
同步操作将从 dreamans/syncd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright 2019 syncd Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package syncd
import (
"errors"
"encoding/base64"
"fmt"
"os"
"io"
"github.com/gin-gonic/gin"
"github.com/dreamans/syncd/util/golog"
"github.com/dreamans/syncd/util/gopath"
)
var (
App *syncd
)
const (
Version = "v2.0.0"
)
func init() {
App = newSyncd()
}
type syncd struct {
Gin *gin.Engine
DB *DB
Logger *golog.Logger
Mail *SendMail
LocalSpace string
LocalTmpSpace string
LocalTarSpace string
RemoteSpace string
CipherKey []byte
AppHost string
FeServeEnable int
config *Config
}
func newSyncd() *syncd {
return &syncd{
Gin: gin.New(),
}
}
func (s *syncd) Init(cfg *Config) error {
s.config = cfg
if err := s.registerOrm(); err != nil {
return err
}
s.registerMail()
s.registerLog()
if err := s.initEnv(); err != nil {
return err
}
return nil
}
func (s *syncd) Start() error {
return s.Gin.Run(s.config.Serve.Addr)
}
func (s *syncd) registerOrm() error {
s.DB = NewDatabase(s.config.Db)
return s.DB.Open()
}
func (s *syncd) registerLog() {
var loggerHandler io.Writer
switch s.config.Log.Path {
case "stdout":
loggerHandler = os.Stdout
case "stderr":
loggerHandler = os.Stderr
case "":
loggerHandler = os.Stdout
default:
loggerHandler = golog.NewFileHandler(s.config.Log.Path)
}
s.Logger = golog.New(loggerHandler)
}
func (s *syncd) registerMail() {
sendmail := &SendMail{
Enable: s.config.Mail.Enable,
Smtp: s.config.Mail.Smtp,
Port: s.config.Mail.Port,
User: s.config.Mail.User,
Pass: s.config.Mail.Pass,
}
s.Mail = NewSendMail(sendmail)
}
func (s *syncd) initEnv() error {
s.AppHost = s.config.Syncd.AppHost
s.FeServeEnable = s.config.Serve.FeServeEnable
s.LocalSpace = s.config.Syncd.LocalSpace
s.LocalTmpSpace = s.LocalSpace + "/tmp"
s.LocalTarSpace = s.LocalSpace + "/tar"
if err := gopath.CreatePath(s.LocalSpace); err != nil {
return err
}
if err := gopath.CreatePath(s.LocalTmpSpace); err != nil {
return err
}
if err := gopath.CreatePath(s.LocalTarSpace); err != nil {
return err
}
s.RemoteSpace = s.config.Syncd.RemoteSpace
if s.config.Syncd.Cipher == "" {
return errors.New("syncd config 'Cipher' not setting")
}
dec, err := base64.StdEncoding.DecodeString(s.config.Syncd.Cipher)
if err != nil {
return errors.New(fmt.Sprintf("decode Cipher failed, %s", err.Error()))
}
s.CipherKey = dec
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。