mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-06 11:08:19 +00:00
parent
67107de377
commit
9fa96acfb2
4
main.go
4
main.go
|
@ -40,6 +40,10 @@ func main() {
|
|||
conf.HookLogDir = os.TempDir()
|
||||
}
|
||||
|
||||
if err := conf.Validate(); err != nil {
|
||||
logger.Error.Fatal("invalid configuration:", err)
|
||||
}
|
||||
|
||||
logger.Debug.Println("starting webhookd server...")
|
||||
|
||||
srv := server.NewServer(conf)
|
||||
|
|
|
@ -42,6 +42,7 @@ func buildMiddlewares(conf *config.Config) middleware.Middlewares {
|
|||
|
||||
func routes(conf *config.Config) Routes {
|
||||
middlewares := buildMiddlewares(conf)
|
||||
staticPath := conf.StaticPath + "/"
|
||||
return Routes{
|
||||
route(
|
||||
"/",
|
||||
|
@ -49,8 +50,8 @@ func routes(conf *config.Config) Routes {
|
|||
middlewares.UseBefore(middleware.Methods("GET", "POST"))...,
|
||||
),
|
||||
route(
|
||||
"/static/",
|
||||
static("/static/"),
|
||||
staticPath,
|
||||
static(staticPath),
|
||||
middlewares.UseBefore(middleware.Methods("GET"))...,
|
||||
),
|
||||
route(
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// Config contain global configuration
|
||||
type Config struct {
|
||||
ListenAddr string `flag:"listen-addr" desc:"HTTP listen address" default:":8080"`
|
||||
|
@ -15,6 +20,14 @@ type Config struct {
|
|||
PasswdFile string `flag:"passwd-file" desc:"Password file for basic HTTP authentication" default:".htpasswd"`
|
||||
LogLevel string `flag:"log-level" desc:"Log level (debug, info, warn, error)" default:"info"`
|
||||
StaticDir string `flag:"static-dir" desc:"Static file directory to serve on /static path" default:""`
|
||||
StaticPath string `flag:"static-path" desc:"Path to serve static file directory" default:"/static"`
|
||||
NotificationURI string `flag:"notification-uri" desc:"Notification URI"`
|
||||
TrustStoreFile string `flag:"trust-store-file" desc:"Trust store used by HTTP signature verifier (.pem or .p12)"`
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if matched, _ := regexp.MatchString(`^/\w+$`, c.StaticPath); !matched {
|
||||
return fmt.Errorf("invalid static path: %s", c.StaticPath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user