drone_plugin/main.go

49 lines
900 B
Go
Raw Normal View History

2021-12-28 15:20:31 +08:00
package main
import (
"net/http"
2021-12-28 16:23:53 +08:00
"github.com/drone/drone-go/plugin/config"
2021-12-28 15:20:31 +08:00
"github.com/sirupsen/logrus"
"git.icechen.cn/pkg/drone_plugin/go_coverter"
"github.com/kelseyhightower/envconfig"
)
// spec provides the plugin settings.
type spec struct {
Bind string `envconfig:"DRONE_BIND"`
Debug bool `envconfig:"DRONE_DEBUG"`
Secret string `envconfig:"DRONE_SECRET"`
}
func main() {
spec := new(spec)
err := envconfig.Process("", spec)
if err != nil {
logrus.Fatal(err)
}
if spec.Debug {
logrus.SetLevel(logrus.DebugLevel)
}
if spec.Secret == "" {
logrus.Fatalln("missing secret key")
}
if spec.Bind == "" {
spec.Bind = ":3000"
}
2021-12-28 16:23:53 +08:00
handler := config.Handler(
2021-12-28 15:20:31 +08:00
go_coverter.New(),
spec.Secret,
logrus.StandardLogger(),
)
logrus.Infof("server listening on address %s", spec.Bind)
http.Handle("/", handler)
logrus.Fatal(http.ListenAndServe(spec.Bind, nil))
}