github.com/vseinstrumentiru/lego@v1.0.2/internal/lego/transport/http/config.go (about)

     1  package http
     2  
     3  import (
     4  	"emperror.dev/errors"
     5  	"github.com/spf13/pflag"
     6  	"github.com/spf13/viper"
     7  	lego2 "github.com/vseinstrumentiru/lego/internal/lego"
     8  )
     9  
    10  type Config struct {
    11  	lego2.WithSwitch `mapstructure:",squash"`
    12  	IsPublic         bool
    13  
    14  	Port int
    15  }
    16  
    17  func (c Config) SetDefaults(env *viper.Viper, flag *pflag.FlagSet) {
    18  	flag.Int("http-port", 8080, "HTTP server port")
    19  	_ = env.BindPFlag("srv.http.port", flag.Lookup("http-port"))
    20  	env.SetDefault("srv.http.port", 8080)
    21  }
    22  
    23  func (c Config) Validate() (err error) {
    24  	if c.Enabled {
    25  		if c.Port == 0 {
    26  			err = errors.Append(err, errors.New("srv.http.port is required"))
    27  		}
    28  	}
    29  
    30  	return
    31  }