GoLang后端开发随笔
目录
GoLang后端开发随笔
开发日常使用命令:
#启动consul
consul agent -dev
#启动micro网关 默认是8080端口,可指定端口
micro --registry=consul api --handler=api
micro --registry=consul api --handler=api --address=:8099 #(指定端口号)
#启动各个服务,并注册到consul
go run main.go plugin.go --registry=consul
#protoc生成文件
protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=. *.proto
# 查看微服务详细信息
curl -s 127.0.0.1:8500/v1/agent/services
# 彻底杀服务
# 查找到端口用
netstat -lnp|grep 80 # 找到进程号
ps -ef|grep <进程号>
kill -9 <进程号> #杀掉
# NSQ具体使用(调试程序时建议不要启动后台模式,方便重新启停mq):
# 开启nsqlookupd服务
nohup ./nsqlookupd > /dev/null 2>&1 &
# 不后台启动则直接
nsqlookupd
# 开启nsqd服务
nohup ./nsqd --lookupd-tcp-address=127.0.0.1:4160 > /dev/null 2>&1 &
# 不设置后台启动则直接
nsqd --lookupd-tcp-address=127.0.0.1:4160
# 开启nsqadmin服务(如不开启浏览器端mq可视化界面,可不启动)
nohup ./nsqadmin --lookupd-http-address=127.0.0.1:4161 > /dev/null 2>&1 &
# 不设置后台启动则直接
nsqadmin --lookupd-http-address=127.0.0.1:4161
// protoc 语法
syntax = "proto3";
package go.micro.srv.InstOntologyMode;
service InstOntologyMode {
rpc AddEdges(EdgeMessage) returns (Result) {}
rpc AddModule(DesignModuleMessage) returns (Result) {}
rpc AddNodes(NodeMessage) returns (Result) {}
rpc DeleteEdges(EdgeMessage) returns (Result) {}
rpc DeleteNodes(NodeMessage) returns (Result) {}
rpc UpdateEdge(EdgeMessage) returns (Result) {}
rpc UpdateNode(NodeMessage) returns (Result) {}
}
message NodeMessage{
InstOntologyNodeMs InstOntologyNodeMs = 1;
string Label =2;
}
message EdgeMessage{
InstOntologyEdgeMs InstOntologyEdgeMs = 1;
string Label =2;
}
message DesignModuleMessage{
DesignModuleMs DesignModuleMs = 1;
string Label =2;
}
message Result{
string Tag = 1;
string Data = 2;
}
message Attr{
string Name = 1;
string Type = 2;
string Value = 3;
string Common = 4;
}
message InstOntologyNode{
string Id = 1;
string Name = 2;
string Class = 3;
repeated Attr Attrs = 4;
string Source = 5;
}
message InstOntologyEdge{
string Id = 1;
string SourceId = 2;
string TargetId = 3;
}
message InstOntologyNodeMs{
repeated InstOntologyNode Nodes = 1;
string ProjectName = 2;
string UserName = 3;
string Source = 4;
}
message InstOntologyEdgeMs{
repeated InstOntologyEdge Edges = 1;
string ProjectName = 2;
string UserName = 3;
string Source = 4;
}
message DesignModuleMs{
string ModuleId = 1;
string ProjectName = 2;
string UserName = 3;
string Source = 4;
}