mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
40 lines
732 B
Go
40 lines
732 B
Go
package gotsrpc
|
|
|
|
import (
|
|
"io/ioutil"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type GoTypeScriptMapping struct {
|
|
GoPackage string `yaml:"-"`
|
|
TypeScriptDir string `yaml:"dir"`
|
|
TypeScriptModule string `yaml:"module"`
|
|
}
|
|
|
|
type Config struct {
|
|
Mappings map[string]*GoTypeScriptMapping
|
|
}
|
|
|
|
func loadConfigfile(file string) (conf *Config, err error) {
|
|
yamlBytes, readErr := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
err = readErr
|
|
return
|
|
}
|
|
return loadConfig(yamlBytes)
|
|
}
|
|
|
|
func loadConfig(yamlBytes []byte) (conf *Config, err error) {
|
|
conf = &Config{}
|
|
yamlErr := yaml.Unmarshal(yamlBytes, conf)
|
|
if yamlErr != nil {
|
|
err = yamlErr
|
|
return
|
|
}
|
|
for goPackage, mapping := range conf.Mappings {
|
|
mapping.GoPackage = goPackage
|
|
}
|
|
return
|
|
}
|