package main import ( "io/ioutil" "gopkg.in/yaml.v3" ) const DefaultConfigFile = ".drone.yml" type Config struct { Kind string `json:"kind" yaml:"kind"` Type string `json:"type" yaml:"type"` Name string `json:"name" yaml:"name"` Api ApiList `json:"api" yaml:"api"` Service ServiceList `json:"service" yaml:"service"` } type ( ApiList []Api Api struct { Name string `json:"name" yaml:"name"` Root string `json:"root" yaml:"root"` Type string `json:"type" yaml:"type"` Port string `json:"port" yaml:"port"` } ) type ( ServiceList []Service Service struct { Name string `json:"name" yaml:"name"` Root string `json:"root" yaml:"root"` Type string `json:"type" yaml:"type"` Port string `json:"port" yaml:"port"` } ) var config Config func ReadConfig() error { configFile, err := ioutil.ReadFile(DefaultConfigFile) if err != nil { return err } err = yaml.Unmarshal(configFile, &config) if err != nil { return err } return nil } func (al ApiList) HasApp(appNameList []string) ApiList { if len(appNameList) == 0 { return al } hasApp := make(ApiList, 0, len(al)) al: for _, api := range al { for _, a := range appNameList { if a == api.Name { hasApp = append(hasApp, api) continue al } } } return hasApp }