代码拉取完成,页面将自动刷新
package main
import (
"flag"
"net/http"
"os"
"strconv"
"sync-bot/git"
"sync-bot/gitee"
"sync-bot/hook"
"sync-bot/secret"
"github.com/emicklei/go-restful/v3"
"github.com/sirupsen/logrus"
)
func init() {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{
DisableColors: true,
FullTimestamp: true,
})
}
type options struct {
//dryRun bool //
giteeToken string //
port int //
webhookSecret string //
}
func (o *options) Validate() error {
return nil
}
func gatherOptions(fs *flag.FlagSet, args ...string) options {
var o options
//fs.BoolVar(&o.dryRun, "dry-run", true, "Dry run for testing. Uses API tokens but does not mutate.")
fs.StringVar(&o.giteeToken, "gitee-token", "token.conf", "Path to the file containing the Gitee token.")
fs.IntVar(&o.port, "port", 8765, "Port to listen on.")
fs.StringVar(&o.webhookSecret, "webhook-secret", "secret.conf", "Path to the file containing the Gitee Webhook secret.")
_ = fs.Parse(args)
return o
}
func main() {
o := gatherOptions(flag.NewFlagSet(os.Args[0], flag.ExitOnError), os.Args[1:]...)
if err := o.Validate(); err != nil {
logrus.WithError(err).Fatal("Invalid options")
}
err := secret.LoadSecrets([]string{o.giteeToken, o.webhookSecret})
if err != nil {
logrus.WithError(err).Fatal("Load secret failed.")
}
gitClient, err := git.NewClient()
if err != nil {
logrus.WithError(err).Fatalf("New git client failed: %v", err)
}
// TODO: user must be configurable
gitClient.SetCredentials("openeuler-sync-bot", secret.GetGenerator(o.giteeToken))
server := hook.Server{
GitClient: gitClient,
GiteeClient: gitee.NewClient(secret.GetGenerator(o.giteeToken)),
Secret: secret.GetGenerator(o.webhookSecret),
}
restful.Add(server.WebService())
port := ":" + strconv.Itoa(o.port)
logrus.WithFields(logrus.Fields{
"Option": o,
}).Infoln("Listen...")
logrus.Fatal(http.ListenAndServe(port, nil))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。