go-toml.go 833 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2017 The go-vgo Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // https://github.com/go-vgo/gt/blob/master/LICENSE
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. // +build !toml
  11. package conf
  12. import (
  13. "io/ioutil"
  14. "log"
  15. "github.com/pelletier/go-toml"
  16. )
  17. // Init toml config
  18. func Init(filePath string, config interface{}) {
  19. confLock.Lock()
  20. fileBytes, err := ioutil.ReadFile(filePath)
  21. if err != nil {
  22. log.Fatal("ioutil.ReadFile error: ", err)
  23. }
  24. toml.Unmarshal(fileBytes, config)
  25. confLock.Unlock()
  26. }