github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/orderer/config/v2/io.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package v2 20 21 import ( 22 "io/ioutil" 23 "path/filepath" 24 25 "sigs.k8s.io/yaml" 26 ) 27 28 func ReadOrdererFile(path string) (*Orderer, error) { 29 config, err := ioutil.ReadFile(filepath.Clean(path)) 30 if err != nil { 31 return nil, err 32 } 33 34 orderer := &Orderer{} 35 err = yaml.Unmarshal(config, orderer) 36 if err != nil { 37 return nil, err 38 } 39 40 return orderer, nil 41 } 42 43 func ReadOrdererFromBytes(config []byte) (*Orderer, error) { 44 orderer := &Orderer{} 45 err := yaml.Unmarshal(config, orderer) 46 if err != nil { 47 return nil, err 48 } 49 50 return orderer, nil 51 } 52 53 func ReadFrom(from *[]byte) (*Orderer, error) { 54 ordererConfig := &Orderer{} 55 err := yaml.Unmarshal(*from, ordererConfig) 56 if err != nil { 57 return nil, err 58 } 59 60 return ordererConfig, nil 61 }