drone_plugin/main.go

48 lines
905 B
Go
Raw Normal View History

2021-12-28 15:20:31 +08:00
package main
import (
"net/http"
"github.com/sirupsen/logrus"
"git.icechen.cn/pkg/drone_plugin/go_coverter"
"github.com/drone/drone-go/plugin/converter"
"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"
}
handler := converter.Handler(
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))
}