浏览代码

init repo

joe 4 年之前
当前提交
1c317d1242
共有 6 个文件被更改,包括 154 次插入0 次删除
  1. 6 0
      .gitignore
  2. 19 0
      Makefile
  3. 11 0
      README.md
  4. 69 0
      basic.proto
  5. 20 0
      enums.proto
  6. 29 0
      errors.proto

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+*.pb.go
+*.py
+*.php
+*.c
+*.c
+*.cpp

+ 19 - 0
Makefile

@@ -0,0 +1,19 @@
+
+# protoc is required:
+# pacman -S protoc
+# apt install protoc
+.PHONY: all go python clean
+
+all: go python
+
+# protoc-gen-go is required:
+# go install github.com/golang/protobuf/protoc-gen-go@latest
+go:
+	protoc --go_out=paths=source_relative:. *.proto
+
+python:
+	protoc --python_out=. *.proto
+
+clean:
+	-@rm *_pb2.py
+	-@rm *.pb.go

+ 11 - 0
README.md

@@ -0,0 +1,11 @@
+# cproto means common proto
+
+It simply support several basic definitions cross languages.
+
+# How to generate
+
+`make / make all` generates golang and python files.
+
+`make go` generates golang files only while `make python` generates python files only.
+
+`make clean` will remove all generated files.

+ 69 - 0
basic.proto

@@ -0,0 +1,69 @@
+syntax = "proto3";
+package cproto;
+
+option go_package = "./;cproto";
+
+// net address
+message Address {
+    string  ip      = 1;
+    int32   port    = 2;
+}
+
+message Scope {
+    int32   min     = 1;
+    int32   max     = 2;
+}
+
+// support MySQL, Postgresql, redis etc.
+message StoreConf {
+    string  type        = 1;
+    string  addr        = 2;    // host:port
+    string  username    = 3;
+    string  password    = 4;
+    int32   timeout     = 5;
+    string  db          = 6;    // to int32 if db refer a redis db.
+}
+
+message ClusterConf {
+    repeated string addrs   = 1;
+    string  username        = 2;
+    string  password        = 3;
+    string  cluster_id      = 4;
+    int32   timeout         = 5;
+    string  db              = 6;
+}
+
+message LogConf {
+    string  path        = 1;
+    string  level       = 2;
+    int32   max_size    = 3;
+    int32   max_age     = 4;
+    int32   max_backups = 5;
+    int32   compress    = 6;
+}
+
+message MessageTemplate {
+    string  subject     = 1;
+    string  body        = 2;
+}
+
+message SmtpConf {
+    string  server      = 1;
+    int32   port        = 2;
+    string  username    = 3;
+    string  password    = 4;
+    string  crypto      = 5;
+}
+
+message SmsTemplate {
+    string  code        = 1;
+    string  params      = 2;
+}
+
+message SmsConf {
+    string  provider    = 1;
+    string  sign_name   = 2;
+    string  region      = 3; // needed sometimes
+    string  access_key  = 4;
+    string  secret_key  = 5;
+}

+ 20 - 0
enums.proto

@@ -0,0 +1,20 @@
+syntax = "proto3";
+package cproto;
+
+option go_package = "./;cproto";
+
+enum ClientPlatform {
+    WIN32       = 0;
+    LINUX       = 1;    // UNIX included.
+    MACOS       = 2;
+    ANDROID     = 3;
+    IOS         = 4;
+    H5          = 5;
+}
+
+enum Gender {
+    FEMALE      = 0;
+    MALE        = 1;
+    UNKNOWN     = 2;
+}
+

+ 29 - 0
errors.proto

@@ -0,0 +1,29 @@
+syntax = "proto3";
+package cproto;
+
+option go_package = "./;cproto";
+
+// error code
+enum Ec {
+    SUC                 = 0;
+    PARAMS_INVALID      = 1;
+    MEMORY_INFUFFICENT  = 2;
+    OUT_OF_RANGE        = 3;
+    TIMEOUT             = 4;
+    TARGET_NOT_FOUND    = 30;
+    TARGET_HAS_EXIST    = 31;
+    DISCONNECTED        = 50;
+    AUTH_FAILED         = 60;
+}
+
+enum NetClosedReason {
+    UNKNOWN         = 0;
+    ERR_NETWORK     = 1;
+    ILLEGAL_DATA    = 2;
+    SERVER_KICK     = 3;
+    HEARTBEAT       = 4;
+    ERR_AUTH        = 5;
+    DUPLICATED      = 6;
+    FORBIDDEN       = 7;
+    MAINTAINING     = 8;
+}