-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use viper to parse config from a yaml file. Mulitple paths are check for the config file to exist (cwd, userConfigDir, src/openem-ingestor/core)
- Loading branch information
1 parent
d1039d4
commit 92f3dc3
Showing
7 changed files
with
184 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Scicat: | ||
Host: http://openem-scopem.ethz.ch:89/api/v3 | ||
AccessToken: "asdf" | ||
Transfer: | ||
Method: S3 | ||
S3: | ||
Endpoint: scopem-openem.ethz.ch:9000 | ||
Bucket: landingzone | ||
Checksum: true | ||
Globus: | ||
Endpoint: globus.psi.ch | ||
Misc: | ||
ConcurrencyLimit: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
type Scicat struct { | ||
Host string `string:"Host"` | ||
AccessToken string `string:"AccessToken"` | ||
} | ||
|
||
type S3 struct { | ||
Endpoint string `string:"Endpoint"` | ||
Bucket string `string:"Bucket"` | ||
Checksum bool `bool:"Checksum"` | ||
} | ||
|
||
type Globus struct { | ||
Endpoint string `string:"Endpoint"` | ||
} | ||
|
||
type Transfer struct { | ||
Method string `string:"Method"` | ||
S3 S3 `mapstructure:"S3"` | ||
Globus Globus `mapstructure:"Globus"` | ||
} | ||
|
||
type Misc struct { | ||
ConcurrencyLimit int `int:"ConcurrencyLimit"` | ||
} | ||
|
||
type Config struct { | ||
Scicat Scicat `mapstructure:"Scicat"` | ||
Transfer Transfer `mapstructure:"Transfer"` | ||
Misc Misc `mapstructure:"Misc"` | ||
} | ||
|
||
func GetConfig() (Config, error) { | ||
var config Config | ||
if err := viper.Unmarshal(&config); err != nil { | ||
fmt.Println(err) | ||
return config, err | ||
} | ||
return config, nil | ||
} | ||
|
||
func ReadConfig() error { | ||
viper.SetConfigName(".openem-ingestor-config") // name of config file (without extension) | ||
viper.SetConfigType("yaml") | ||
|
||
userConfigDir, _ := os.UserConfigDir() | ||
viper.AddConfigPath(userConfigDir) | ||
|
||
// these paths are mostly for development | ||
viper.AddConfigPath("./") | ||
viper.AddConfigPath("./core") | ||
|
||
err := viper.ReadInConfig() | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters