Metrics
0
Watch 118 Star 509 Fork 129

GVPdreamans / syncdGoMIT

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
syncd是一款开源的代码部署工具,它具有简单、高效、易用等特点,可以提高团队的工作效率. spread retract

https://syncd.cc

  • Go 50.1%
  • Vue 39.4%
  • JavaScript 7.8%
  • CSS 1.7%
  • HTML 0.6%
  • Other 0.4%
Clone or download
syncd.go 2.81 KB
Copy Edit Web IDE Raw Blame History
dreamans authored 2019-03-27 11:25 . packfile empty 异常处理
// 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
}

Comment ( 0 )

You need to Sign in for post a comment

Help Search