...

Source file src/github.com/palantir/go-baseapp/example/config.go

Documentation: github.com/palantir/go-baseapp/example

     1  // Copyright 2018 Palantir Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"io/ioutil"
    19  
    20  	"github.com/palantir/go-baseapp/baseapp"
    21  	"github.com/palantir/go-baseapp/baseapp/datadog"
    22  	"github.com/pkg/errors"
    23  	"gopkg.in/yaml.v2"
    24  )
    25  
    26  type Config struct {
    27  	Server  baseapp.HTTPConfig    `yaml:"server"`
    28  	Datadog datadog.Config        `yaml:"datadog"`
    29  	Logging baseapp.LoggingConfig `yaml:"logging"`
    30  
    31  	App AppConfig `yaml:"app"`
    32  }
    33  
    34  type AppConfig struct {
    35  	Message string `yaml:"message"`
    36  }
    37  
    38  func ReadConfig(path string) (Config, error) {
    39  	var c Config
    40  
    41  	bytes, err := ioutil.ReadFile(path)
    42  	if err != nil {
    43  		return c, errors.Wrapf(err, "failed reading server config file: %s", path)
    44  	}
    45  
    46  	if err := yaml.UnmarshalStrict(bytes, &c); err != nil {
    47  		return c, errors.Wrap(err, "failed parsing configuration file")
    48  	}
    49  
    50  	return c, nil
    51  }
    52  

View as plain text