50 lines
907 B
Go
50 lines
907 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.icechen.cn/pkg/drone_plugin/config_handler"
|
|
|
|
"github.com/drone/drone-go/plugin/config"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"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 := config.Handler(
|
|
config_handler.New(),
|
|
spec.Secret,
|
|
logrus.StandardLogger(),
|
|
)
|
|
|
|
logrus.Infof("server listening on address %s", spec.Bind)
|
|
|
|
http.Handle("/", handler)
|
|
logrus.Fatal(http.ListenAndServe(spec.Bind, nil))
|
|
}
|