* refactor(report): LocalFileWriter * refactor -format-json * refacotr: -format-one-email * refactor: -format-csv * refactor: -gzip * refactor: -format-full-text * refactor: -format-one-line-text * refactor: -format-list * refacotr: remove -to-* from config * refactor: IgnoreGitHubDismissed * refactor: GitHub * refactor: IgnoreUnsocred * refactor: diff * refacotr: lang * refacotr: cacheDBPath * refactor: Remove config references * refactor: ScanResults * refacotr: constant pkg * chore: comment * refactor: scanner * refactor: scanner * refactor: serverapi.go * refactor: serverapi * refactor: change pkg structure * refactor: serverapi.go * chore: remove emtpy file * fix(scan): remove -ssh-native-insecure option * fix(scan): remove the deprecated option `keypassword`
40 lines
684 B
Go
40 lines
684 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/asaskevich/govalidator"
|
|
)
|
|
|
|
// HTTPConf is HTTP config
|
|
type HTTPConf struct {
|
|
URL string `valid:"url" json:"-"`
|
|
Enabled bool `toml:"-" json:"-"`
|
|
}
|
|
|
|
// Validate validates configuration
|
|
func (c *HTTPConf) Validate() (errs []error) {
|
|
if !c.Enabled {
|
|
return nil
|
|
}
|
|
|
|
if _, err := govalidator.ValidateStruct(c); err != nil {
|
|
errs = append(errs, err)
|
|
}
|
|
return errs
|
|
}
|
|
|
|
const httpKey = "VULS_HTTP_URL"
|
|
|
|
// Init set options with the following priority.
|
|
// 1. Environment variable
|
|
// 2. config.toml
|
|
func (c *HTTPConf) Init(url string) {
|
|
if os.Getenv(httpKey) != "" {
|
|
c.URL = os.Getenv(httpKey)
|
|
}
|
|
if url != "" {
|
|
c.URL = url
|
|
}
|
|
}
|