github.com/wtfutil/wtf@v0.43.0/modules/airbrake/settings.go (about)

     1  package airbrake
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  
     7  	"github.com/olebedev/config"
     8  	"github.com/wtfutil/wtf/cfg"
     9  )
    10  
    11  const (
    12  	defaultFocusable = true
    13  	defaultTitle     = "Airbrake"
    14  )
    15  
    16  type Settings struct {
    17  	*cfg.Common
    18  
    19  	projectID int    `help:"The id of your Airbrake project."`
    20  	authToken string `help:"The token that allows accessing Airbrake API"`
    21  }
    22  
    23  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    24  	settings := Settings{
    25  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle,
    26  			defaultFocusable, ymlConfig, globalConfig),
    27  		projectID: ymlConfig.UInt("projectID", getProjectID()),
    28  		authToken: ymlConfig.UString("authToken", os.Getenv("AIRBRAKE_USER_KEY")),
    29  	}
    30  
    31  	cfg.ModuleSecret(name, globalConfig, &settings.authToken).Load()
    32  
    33  	return &settings
    34  }
    35  
    36  func getProjectID() int {
    37  	projectID, err := strconv.ParseInt(os.Getenv("AIRBRAKE_PROJECT_ID"), 10, 32)
    38  	if err != nil {
    39  		return 0
    40  	}
    41  
    42  	return int(projectID)
    43  }