Files
go-snipcart/snipcart/webhook/config.go
2023-02-26 20:36:12 -05:00

34 lines
785 B
Go

package webhook
import (
"bytes"
"encoding/json"
"io/ioutil"
"github.com/debyltech/go-shippr/shippo"
)
type Config struct {
ShippoApiKey string `json:"shippo_api_key"`
WeightUnit string `json:"weight_unit"`
DimensionUnit string `json:"dimension_unit"`
ManufactureCountry string `json:"manufacture_country"`
SenderAddress shippo.Address `json:"sender_address"`
DefaultParcel shippo.Parcel `json:"default_parcel"`
}
func NewConfigFromFile(filePath string) (*Config, error) {
configBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
var config Config
err = json.NewDecoder(bytes.NewBuffer(configBytes)).Decode(&config)
if err != nil {
return nil, err
}
return &config, nil
}