github.com/turingchain2020/turingchain@v1.1.21/cmd/tools/gencode/dappcode/proto/proto.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package proto 6 7 import ( 8 "github.com/turingchain2020/turingchain/cmd/tools/gencode/base" 9 "github.com/turingchain2020/turingchain/cmd/tools/types" 10 ) 11 12 func init() { 13 14 base.RegisterCodeFile(protoBase{}) 15 base.RegisterCodeFile(protoFile{}) 16 } 17 18 type protoBase struct { 19 base.DappCodeFile 20 } 21 22 func (protoBase) GetDirName() string { 23 24 return "proto" 25 } 26 27 func (protoBase) GetFiles() map[string]string { 28 29 return map[string]string{ 30 protoShellName: protoShellContent, 31 makeName: makeContent, 32 } 33 } 34 35 func (protoBase) GetFileReplaceTags() []string { 36 return []string{types.TagExecName} 37 } 38 39 type protoFile struct { 40 protoBase 41 } 42 43 func (protoFile) GetFiles() map[string]string { 44 return map[string]string{ 45 protoFileName: protoFileContent, 46 } 47 } 48 49 func (protoFile) GetFileReplaceTags() []string { 50 return []string{types.TagProtoFileContent, types.TagProtoFileAppend, types.TagExecName} 51 } 52 53 var ( 54 protoShellName = "create_protobuf.sh" 55 protoShellContent = `#!/bin/bash 56 # proto生成命令,将pb.go文件生成到types/目录下, turingchain_path支持引用turingchain框架的proto文件 57 turingchain_path=$(go list -f '{{.Dir}}' "github.com/turingchain2020/turingchain") 58 protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="${turingchain_path}/types/proto/" 59 ` 60 61 makeName = "Makefile" 62 makeContent = `all: 63 bash ./create_protobuf.sh 64 ` 65 66 protoFileName = "${EXECNAME}.proto" 67 protoFileContent = `${PROTOFILECONTENT} 68 ${PROTOFILEAPPEND}` 69 )