github.com/klaytn/klaytn@v1.12.1/cmd/homi/setup/klaytn_config.go (about) 1 // Copyright 2018 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The klaytn library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package setup 18 19 import ( 20 "bytes" 21 "fmt" 22 "text/template" 23 ) 24 25 type KlaytnConfig struct { 26 NetworkId int 27 RPCPort int 28 WSPort int 29 P2PPort int 30 DataDir string 31 LogDir string 32 RunDir string 33 NodeType string 34 } 35 36 func NewKlaytnConfig(networkId int, rpcPort int, wsPort int, p2pPort int, dataDir string, logDir string, runDir string, nodeType string) *KlaytnConfig { 37 kConf := &KlaytnConfig{ 38 NetworkId: networkId, 39 RPCPort: rpcPort, 40 WSPort: wsPort, 41 P2PPort: p2pPort, 42 DataDir: dataDir, 43 LogDir: logDir, 44 RunDir: runDir, 45 NodeType: nodeType, 46 } 47 return kConf 48 } 49 50 func (k KlaytnConfig) String() string { 51 tmpl, err := template.New("KlaytnConfig").Parse(kTemplate) 52 if err != nil { 53 fmt.Printf("Failed to parse template, %v", err) 54 return "" 55 } 56 57 res := new(bytes.Buffer) 58 err = tmpl.Execute(res, k) 59 if err != nil { 60 fmt.Printf("Failed to render template, %v", err) 61 return "" 62 } 63 64 return res.String() 65 } 66 67 var kTemplate = `# Configuration file for the klay service. 68 69 NETWORK_ID={{ .NetworkId }} 70 71 RPC_PORT={{ .RPCPort }} 72 WS_PORT={{ .WSPort }} 73 PORT={{ .P2PPort }} 74 75 DATA_DIR={{ .DataDir }} 76 LOG_DIR={{ .LogDir }} 77 RUN_DIR={{ .RunDir }} 78 79 # NODE_TYPE [CN, PN, RN] 80 NODE_TYPE={{ .NodeType }} 81 `