/
common.go
69 lines (59 loc) · 1.42 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package entity
import (
"os"
"path/filepath"
"runtime"
)
var (
templateDir = "template"
blockDir = "block"
configDir = "config"
peerDir = filepath.Join(configDir, "peer")
OrdererDir = filepath.Join(configDir, "orderer")
channelDir = filepath.Join(configDir, "channel")
mspDir = filepath.Join(configDir, "msp")
tempDir = filepath.Join(configDir, "tmp")
binDir = filepath.Join("bin",runtime.GOOS,runtime.GOARCH)
peerBin = filepath.Join(binDir, "peer")
ordererBin = filepath.Join(binDir, "orderer")
configtxyml = "configtx.yaml"
configyml = "config.yaml"
ordereryml = "orderer.yaml"
coreYml = "core.yaml"
channel = "channel"
defaultMspDir = "msp"
peers = "peers"
consortiums = "consortiums"
organizations = "organizations"
channels = "channels"
chaincodes = "chaincodes"
orderers = "orderers"
windows = "windows"
)
func Path(paths ...string) string {
path := filepath.Join(paths...)
os.RemoveAll(path)
err := os.MkdirAll(path, 0755)
if err == nil {
return path
}
return ""
}
func SimpleWrite(path string, fileName string, b []byte) error {
file, err := os.Create(filepath.Join(path, fileName))
if err != nil {
return err
}
defer file.Close()
_, err = file.WriteString(string(b))
if err != nil {
return err
}
return nil
}
func WindowsBin(bin string)string{
if(runtime.GOOS == windows){
return bin +".exe"
}
return bin
}