github.com/renbou/grpcbridge@v0.0.2-0.20240416012907-bcbd8b12648a/internal/config/hcl.go (about) 1 package config 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/hcl/v2/hclsimple" 7 ) 8 9 type Bridge struct { 10 Services []Service `hcl:"service,block"` 11 } 12 13 type Service struct { 14 Name string `hcl:"name,label"` 15 Target string `hcl:"target"` 16 } 17 18 func ReadHCL(filename string) (*Bridge, error) { 19 cfg := new(Bridge) 20 21 if err := hclsimple.DecodeFile(filename, nil, cfg); err != nil { 22 return nil, fmt.Errorf("decoding HCL config file: %w", err) 23 } 24 25 return cfg, nil 26 }