func getContext()

in action/log/log.go [72:96]


func getContext() (*model.Cluster, *logadapter.Currency, error) {
	file, err := os.ReadFile("config.yml")
	if err != nil {
		return nil, nil, fmt.Errorf("read config.yml error: %s", err)
	}
	var config model.Config
	err = yaml.Unmarshal(file, &config)
	if err != nil {
		return nil, nil, fmt.Errorf("unmarshal config.yml error: %s", err)
	}
	contextName := config.Context.Log
	for _, cluster := range config.Log.Clusters {
		if cluster.Name == contextName {
			currency := logadapter.Currency{
				Address:  cluster.Address,
				Source:   cluster.Source,
				Username: cluster.Username,
				Password: cluster.Password,
				Index:    cluster.Index,
			}
			return &cluster, &currency, nil
		}
	}
	return nil, nil, fmt.Errorf("failed to find context in config.yml")
}