提交 7fffb0c7 编写于 作者: D Davies Liu

cleanup

上级 05469d37
// Copyright (C) 2018-present Juicedata Inc.
/*
* JuiceFS, Copyright (C) 2018 Juicedata, Inc.
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
......
[bumpversion]
current_version = 0.0.1
commit = True
tag = True
\ No newline at end of file
name: build
on:
pull_request:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Enable cache for go mod
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: go build -v .
- name: Test
run: go test -v ./...
name: release
on:
push:
branches:
- master
- goreleaser
tags:
- v*
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.13.x'
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
dist
juicesync
.idea
.DS_Store
builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X github.com/juicedata/juicesync/versioninfo.VERSION={{.Version}}
- -X github.com/juicedata/juicesync/versioninfo.REVISION={{.Commit}}
- -X github.com/juicedata/juicesync/versioninfo.REVISIONDATE={{.Date}}
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
# Github repository to push the tap to.
tap:
owner: juicedata
name: homebrew-tap
# Folder inside the repository to put the formula.
# Default is the root folder.
folder: Formula
homepage: "https://juicefs.com/"
description: "A tool to move your data between any clouds or regions."
此差异已折叠。
.PHONY: juicesync all
export GO111MODULE=on
all: juicesync
REPO := github.com/juicedata/juicesync
REVISION := $(shell git rev-parse --short HEAD || unknown)
REVISIONDATE := $(shell git log -1 --pretty=format:'%ad' --date short)
VERSION := $(shell git describe --tag)
LDFLAGS ?= -s -w -X $(REPO)/versioninfo.REVISION=$(REVISION) \
-X $(REPO)/versioninfo.REVISIONDATE=$(REVISIONDATE) \
-X $(REPO)/versioninfo.VERSION=$(VERSION)
juicesync:
go build -ldflags="$(LDFLAGS)" -o juicesync
test:
go test ./...
module github.com/juicedata/juicesync
require (
cloud.google.com/go v0.39.0
github.com/Arvintian/scs-go-sdk v1.0.0
github.com/Azure/azure-sdk-for-go v11.1.1-beta+incompatible
github.com/Azure/go-autorest v8.4.0+incompatible // indirect
github.com/IBM/ibm-cos-sdk-go v1.6.0
github.com/NetEase-Object-Storage/nos-golang-sdk v0.0.0-20171031020902-cc8892cb2b05
github.com/aliyun/aliyun-oss-go-sdk v2.1.0+incompatible
github.com/aws/aws-sdk-go v1.12.10
github.com/baidubce/bce-sdk-go v0.0.0-20180401121131-aa0c7bd66b01
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/colinmarc/hdfs/v2 v2.2.0
github.com/dgrijalva/jwt-go v3.0.0+incompatible // indirect
github.com/dnaeon/go-vcr v1.0.1 // indirect
github.com/go-ini/ini v1.28.2 // indirect
github.com/googleapis/gax-go v2.0.0+incompatible // indirect
github.com/huaweicloud/huaweicloud-sdk-go-obs v0.0.0-20190127152727-3a9e1f8023d5
github.com/jcmturner/gokrb5/v8 v8.4.2
github.com/juju/ratelimit v1.0.1
github.com/kr/fs v0.1.0 // indirect
github.com/ks3sdklib/aws-sdk-go v0.0.0-20180820074416-dafab05ad142
github.com/kurin/blazer v0.2.1
github.com/mattn/go-isatty v0.0.4
github.com/onsi/ginkgo v1.13.0 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.10.0
github.com/qiniu/api.v7/v7 v7.8.0
github.com/satori/go.uuid v1.2.0 // indirect
github.com/satori/uuid v1.1.0 // indirect
github.com/sirupsen/logrus v1.0.3
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/tencentyun/cos-go-sdk-v5 v0.7.8
github.com/urfave/cli/v2 v2.1.1
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8
github.com/yunify/qingstor-sdk-go v2.2.15+incompatible
github.com/yunify/qingstor-sdk-go/v3 v3.1.1 // indirect
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07
google.golang.org/api v0.5.0
)
go 1.13
此差异已折叠。
// Copyright 2015 Ka-Hing Cheung
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import (
"fmt"
glog "log"
"log/syslog"
"os"
"strings"
"sync"
"github.com/sirupsen/logrus"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
)
var mu sync.Mutex
var loggers = make(map[string]*logHandle)
type SyslogHook struct {
*logrus_syslog.SyslogHook
}
func (hook *SyslogHook) Fire(entry *logrus.Entry) error {
line, err := entry.String()
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
return err
}
// drop the timestamp
line = line[27:]
switch entry.Level {
case logrus.PanicLevel:
return hook.Writer.Crit(line)
case logrus.FatalLevel:
return hook.Writer.Crit(line)
case logrus.ErrorLevel:
return hook.Writer.Err(line)
case logrus.WarnLevel:
return hook.Writer.Warning(line)
case logrus.InfoLevel:
return hook.Writer.Info(line)
case logrus.DebugLevel:
return hook.Writer.Debug(line)
default:
return nil
}
}
var syslogHook *SyslogHook
func InitLoggers(logToSyslog bool) {
if logToSyslog {
hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_DEBUG|syslog.LOG_USER, "")
if err != nil {
println("Unable to connect to local syslog daemon")
return
}
syslogHook = &SyslogHook{hook}
for _, l := range loggers {
l.Hooks.Add(syslogHook)
}
}
}
type logHandle struct {
logrus.Logger
name string
lvl *logrus.Level
}
func (l *logHandle) Format(e *logrus.Entry) ([]byte, error) {
// Mon Jan 2 15:04:05 -0700 MST 2006
timestamp := ""
lvl := e.Level
if l.lvl != nil {
lvl = *l.lvl
}
const timeFormat = "2006/01/02 15:04:05.000000"
timestamp = e.Time.Format(timeFormat)
str := fmt.Sprintf("%v <%v>: %v",
timestamp,
strings.ToUpper(lvl.String()),
e.Message)
if len(e.Data) != 0 {
str += " " + fmt.Sprint(e.Data)
}
str += "\n"
return []byte(str), nil
}
// for aws.Logger
func (l *logHandle) Log(args ...interface{}) {
l.Debugln(args...)
}
func NewLogger(name string) *logHandle {
l := &logHandle{name: name}
l.Out = os.Stderr
l.Formatter = l
l.Level = logrus.InfoLevel
l.Hooks = make(logrus.LevelHooks)
if syslogHook != nil {
l.Hooks.Add(syslogHook)
}
return l
}
func GetLogger(name string) *logHandle {
mu.Lock()
defer mu.Unlock()
if logger, ok := loggers[name]; ok {
return logger
}
logger := NewLogger(name)
loggers[name] = logger
return logger
}
func GetStdLogger(l *logHandle, lvl logrus.Level) *glog.Logger {
mu.Lock()
defer mu.Unlock()
w := l.Writer()
l.Formatter.(*logHandle).lvl = &lvl
l.Level = lvl
return glog.New(w, "", 0)
}
func SetLogLevel(lvl logrus.Level) {
for _, logger := range loggers {
logger.Level = lvl
}
}
// Copyright (C) 2018-present Juicedata Inc.
package utils
import (
"io"
"os"
)
func Min(a, b int) int {
if a < b {
return a
}
return b
}
func Exists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func CopyFile(dst, src string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, in)
if err != nil {
return err
}
return out.Close()
}
package versioninfo
import "fmt"
var (
NAME = "juicesync"
VERSION = "unknown"
REVISION = "HEAD"
REVISIONDATE = "now"
USAGE = `juicesync [options] SRC DST
SRC and DST should be [NAME://][ACCESS_KEY:SECRET_KEY@]BUCKET[.ENDPOINT][/PREFIX]`
)
func Version() string {
return fmt.Sprintf("%v, commit %v, built at %v", VERSION, REVISION, REVISIONDATE)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册