├── .gitignore ├── .gitmodules ├── Dockerfile ├── Godeps ├── .gitignore ├── Dockerfile ├── Godeps.json ├── Godeps.json.template ├── Readme ├── g.sh ├── legacy.sh └── make_godep.sh ├── LICENSE ├── README.md ├── assets ├── config.toml ├── ip.toml ├── js │ ├── exporting.js │ ├── highcharts.css │ ├── highcharts.js │ ├── highstock.js │ └── jquery-1.8.3.min.js └── server_type.toml ├── build.bat ├── build.sh ├── common ├── app.go ├── args.go ├── args_detail.go ├── init.go ├── k8s │ ├── endpoint.go │ ├── k8s_api_linux.go │ ├── k8s_api_windows.go │ ├── node.go │ ├── node_type.go │ ├── serverlist │ │ ├── node.go │ │ └── servers.go │ └── watch.go ├── log.go ├── service_def.go ├── tcp.go └── web.go ├── common_services ├── bin │ ├── start.bat.sample │ └── stop.bat ├── build.bat ├── db │ ├── Account.go │ ├── Token.go │ ├── UID.go │ ├── UIDServer.go │ ├── g.sh │ └── redis_def │ │ ├── account.json │ │ ├── token.json │ │ └── uidserver.json ├── gateway │ ├── app.go │ ├── args.go │ ├── main.go │ ├── node.go │ ├── session_account.go │ └── session_node.go ├── hub │ ├── app.go │ ├── args.go │ ├── main.go │ └── session_node.go ├── init.go ├── ip.go ├── ip_test.go ├── login │ ├── app.go │ ├── args.go │ ├── login.go │ ├── login_extend.go │ ├── login_msglogin.go │ ├── login_request.go │ └── main.go ├── proto │ ├── common.pb.go │ ├── common.proto │ └── g.sh └── session_intranet.go ├── doc ├── Gateway 的 session affinity 处理.md ├── IO服务器架构图.jpg ├── Lobby 的 session affinity 处理.md ├── assets │ ├── Gateway 的 session affinity 处理.svg │ ├── Lobby 的 session affinity 处理.svg │ ├── 登录时序图1-帐号验证段.svg │ └── 登录时序图2-游戏网关段.svg ├── 消息号规范.md ├── 登录时序图1-帐号验证段.md └── 登录时序图2-游戏网关段.md ├── example1_iogame ├── bin │ ├── start.bat.sample │ └── stop.bat ├── build.bat ├── db │ ├── Role.go │ ├── g.sh │ └── redis_def │ │ └── role.json ├── lobby │ ├── app.go │ ├── args.go │ ├── main.go │ └── session_node.go ├── proto │ ├── g.sh │ ├── lobby.pb.go │ └── lobby.proto ├── room │ ├── app.go │ ├── args.go │ └── main.go └── service_def.go ├── govet.sh ├── k8s ├── gateway.yaml ├── hub.yaml ├── lobby.yaml ├── login.yaml ├── namespace.yaml ├── redis.yaml ├── room.yaml └── service_account.yaml ├── test.sh ├── test └── test_packet_loss │ ├── README.md │ ├── bin │ └── js │ │ ├── exporting.js │ │ ├── highcharts.css │ │ ├── highcharts.js │ │ ├── highstock.js │ │ └── jquery-1.8.3.min.js │ ├── build.bat │ ├── client │ ├── app.go │ ├── chart.go │ ├── main.go │ ├── tcpclient.go │ └── udpclient.go │ └── server │ ├── app.go │ ├── main.go │ ├── tcpserver.go │ └── udpserver.go ├── tools └── redis │ ├── README.md │ ├── docker-stack-redis-cluster.yml │ ├── docker-stack-redis-sentinel.yml │ ├── docker-stack-redis.yml │ ├── install-redis-cluster.sh │ ├── install-redis-sentinel.sh │ └── install-redis.sh └── vendor ├── github.com ├── BurntSushi │ └── toml │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── COMPATIBLE │ │ ├── COPYING │ │ ├── Makefile │ │ ├── README.md │ │ ├── decode.go │ │ ├── decode_meta.go │ │ ├── doc.go │ │ ├── encode.go │ │ ├── encoding_types.go │ │ ├── encoding_types_1.1.go │ │ ├── lex.go │ │ ├── parse.go │ │ ├── session.vim │ │ ├── type_check.go │ │ └── type_fields.go ├── FZambia │ └── sentinel │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ └── sentinel.go ├── bitly │ └── go-simplejson │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── simplejson.go │ │ ├── simplejson_go10.go │ │ └── simplejson_go11.go ├── ericchiang │ └── k8s │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── apis │ │ ├── apiextensions │ │ │ └── v1beta1 │ │ │ │ ├── generated.pb.go │ │ │ │ └── register.go │ │ ├── core │ │ │ └── v1 │ │ │ │ ├── generated.pb.go │ │ │ │ └── register.go │ │ ├── meta │ │ │ └── v1 │ │ │ │ ├── generated.pb.go │ │ │ │ └── json.go │ │ └── resource │ │ │ └── generated.pb.go │ │ ├── client.go │ │ ├── codec.go │ │ ├── config.go │ │ ├── discovery.go │ │ ├── labels.go │ │ ├── resource.go │ │ ├── runtime │ │ ├── generated.pb.go │ │ └── schema │ │ │ └── generated.pb.go │ │ ├── util │ │ └── intstr │ │ │ └── generated.pb.go │ │ ├── watch.go │ │ └── watch │ │ └── versioned │ │ └── generated.pb.go ├── fananchong │ ├── glog │ │ ├── LICENSE │ │ ├── README │ │ ├── glog.go │ │ ├── glog_ext.go │ │ └── glog_file.go │ ├── go-redis-orm.v2 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── LICENSE │ │ ├── README.md │ │ ├── build.sh │ │ ├── common.go │ │ ├── default_redis_client.go │ │ └── redis_mgr.go │ ├── gochart │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── build.bat │ │ ├── chart_base.go │ │ ├── chart_server.go │ │ ├── chart_time.go │ │ ├── log.go │ │ ├── template_time_html.go │ │ └── template_time_html_scrollbars.go │ ├── gomap │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── build.bat │ │ ├── element.go │ │ ├── iterator.go │ │ ├── map_base.go │ │ ├── ordered_map.go │ │ ├── random_map.go │ │ └── roundrobin_map.go │ ├── goredis │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── build.bat │ │ ├── build.sh │ │ ├── cluster.go │ │ ├── option.go │ │ ├── redis.go │ │ ├── sentinel.go │ │ └── standalone.go │ ├── gotcp │ │ ├── .gitignore │ │ ├── .gitmodules │ │ ├── LICENSE │ │ ├── README.md │ │ ├── build.bat │ │ ├── bytebuffer.go │ │ ├── client.go │ │ ├── log.go │ │ ├── protomsg.go │ │ ├── server.go │ │ ├── session.go │ │ ├── session_protomsg.go │ │ └── util.go │ └── multiconfig │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── doc.go │ │ ├── env.go │ │ ├── file.go │ │ ├── flag.go │ │ ├── multiconfig.go │ │ ├── multiloader.go │ │ ├── multivalidator.go │ │ ├── tag.go │ │ └── validator.go ├── fatih │ ├── camelcase │ │ ├── .travis.yml │ │ ├── LICENSE.md │ │ ├── README.md │ │ └── camelcase.go │ └── structs │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── field.go │ │ ├── structs.go │ │ └── tags.go ├── gogo │ └── protobuf │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ └── proto │ │ ├── Makefile │ │ ├── clone.go │ │ ├── decode.go │ │ ├── decode_gogo.go │ │ ├── discard.go │ │ ├── duration.go │ │ ├── duration_gogo.go │ │ ├── encode.go │ │ ├── encode_gogo.go │ │ ├── equal.go │ │ ├── extensions.go │ │ ├── extensions_gogo.go │ │ ├── lib.go │ │ ├── lib_gogo.go │ │ ├── message_set.go │ │ ├── pointer_reflect.go │ │ ├── pointer_reflect_gogo.go │ │ ├── pointer_unsafe.go │ │ ├── pointer_unsafe_gogo.go │ │ ├── properties.go │ │ ├── properties_gogo.go │ │ ├── skip_gogo.go │ │ ├── text.go │ │ ├── text_gogo.go │ │ ├── text_parser.go │ │ ├── timestamp.go │ │ └── timestamp_gogo.go ├── golang │ └── protobuf │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ └── proto │ │ ├── clone.go │ │ ├── decode.go │ │ ├── discard.go │ │ ├── encode.go │ │ ├── equal.go │ │ ├── extensions.go │ │ ├── lib.go │ │ ├── message_set.go │ │ ├── pointer_reflect.go │ │ ├── pointer_unsafe.go │ │ ├── properties.go │ │ ├── table_marshal.go │ │ ├── table_merge.go │ │ ├── table_unmarshal.go │ │ ├── text.go │ │ └── text_parser.go ├── gomodule │ └── redigo │ │ ├── LICENSE │ │ ├── internal │ │ └── commandinfo.go │ │ └── redis │ │ ├── conn.go │ │ ├── doc.go │ │ ├── go16.go │ │ ├── go17.go │ │ ├── go18.go │ │ ├── log.go │ │ ├── pool.go │ │ ├── pool17.go │ │ ├── pubsub.go │ │ ├── redis.go │ │ ├── reply.go │ │ ├── scan.go │ │ └── script.go ├── mna │ └── redisc │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── cluster.go │ │ ├── conn.go │ │ ├── crc16.go │ │ ├── doc.go │ │ ├── hash.go │ │ └── retry_conn.go └── satori │ └── go.uuid │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── codec.go │ ├── generator.go │ ├── sql.go │ └── uuid.go ├── golang.org └── x │ ├── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── http │ │ └── httpguts │ │ │ ├── guts.go │ │ │ └── httplex.go │ ├── http2 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── Makefile │ │ ├── README │ │ ├── ciphers.go │ │ ├── client_conn_pool.go │ │ ├── configure_transport.go │ │ ├── databuffer.go │ │ ├── errors.go │ │ ├── flow.go │ │ ├── frame.go │ │ ├── go16.go │ │ ├── go17.go │ │ ├── go17_not18.go │ │ ├── go18.go │ │ ├── go19.go │ │ ├── gotrack.go │ │ ├── headermap.go │ │ ├── hpack │ │ │ ├── encode.go │ │ │ ├── hpack.go │ │ │ ├── huffman.go │ │ │ └── tables.go │ │ ├── http2.go │ │ ├── not_go16.go │ │ ├── not_go17.go │ │ ├── not_go18.go │ │ ├── not_go19.go │ │ ├── pipe.go │ │ ├── server.go │ │ ├── transport.go │ │ ├── write.go │ │ ├── writesched.go │ │ ├── writesched_priority.go │ │ └── writesched_random.go │ └── idna │ │ ├── idna.go │ │ ├── punycode.go │ │ ├── tables.go │ │ ├── trie.go │ │ └── trieval.go │ └── text │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── secure │ └── bidirule │ │ ├── bidirule.go │ │ ├── bidirule10.0.0.go │ │ └── bidirule9.0.0.go │ ├── transform │ └── transform.go │ └── unicode │ ├── bidi │ ├── bidi.go │ ├── bracket.go │ ├── core.go │ ├── gen.go │ ├── gen_ranges.go │ ├── gen_trieval.go │ ├── prop.go │ ├── tables10.0.0.go │ ├── tables9.0.0.go │ └── trieval.go │ └── norm │ ├── composition.go │ ├── forminfo.go │ ├── input.go │ ├── iter.go │ ├── maketables.go │ ├── normalize.go │ ├── readwriter.go │ ├── tables10.0.0.go │ ├── tables9.0.0.go │ ├── transform.go │ ├── trie.go │ └── triegen.go └── gopkg.in └── yaml.v2 ├── .travis.yml ├── LICENSE ├── LICENSE.libyaml ├── NOTICE ├── README.md ├── apic.go ├── decode.go ├── emitterc.go ├── encode.go ├── go.mod ├── parserc.go ├── readerc.go ├── resolve.go ├── scannerc.go ├── sorter.go ├── writerc.go ├── yaml.go ├── yamlh.go └── yamlprivateh.go /.gitignore: -------------------------------------------------------------------------------- 1 | RemoteSystemsTempFiles 2 | .metadata 3 | *.a 4 | *.exe 5 | bin 6 | .idea 7 | *.toml 8 | .vscode 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/h5client"] 2 | path = tools/h5client 3 | url = https://github.com/fananchong/gox-h5client.git 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | WORKDIR /app/bin 4 | 5 | COPY assets/config.toml /app/bin/config.toml 6 | COPY assets/ip.toml /app/bin/ip.toml 7 | COPY assets/server_type.toml /app/bin/server_type.toml 8 | COPY bin/login /app/bin/login 9 | COPY bin/gateway /app/bin/gateway 10 | COPY bin/hub /app/bin/hub 11 | COPY bin/lobby /app/bin/lobby 12 | COPY bin/room /app/bin/room 13 | 14 | -------------------------------------------------------------------------------- /Godeps/.gitignore: -------------------------------------------------------------------------------- 1 | /src 2 | /bin 3 | -------------------------------------------------------------------------------- /Godeps/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest 2 | 3 | COPY bin/godep / 4 | 5 | ENTRYPOINT ["/godep"] 6 | -------------------------------------------------------------------------------- /Godeps/Godeps.json.template: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "", 3 | "GoVersion": "go1.10", 4 | "GodepVersion": "v80", 5 | "Packages": [ 6 | "./..." 7 | ], 8 | "Deps": [ 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /Godeps/g.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cp -f ./Godeps.json.template ./Godeps.json 4 | cd .. 5 | rm -rf ./vendor 6 | docker run --rm -e GOPATH=/go/:/temp/ -v /temp/:/temp/ -v "$PWD":/go/src/github.com/fananchong/go-x -w /go/src/github.com/fananchong/go-x/ fananchong/godep save ./... 7 | 8 | -------------------------------------------------------------------------------- /Godeps/legacy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | git config http.proxy http://127.0.0.1:8123 6 | git config https.proxy https://127.0.0.1:8123 7 | 8 | export GOPATH=/temp 9 | 10 | go get -u -d github.com/fananchong/glog 11 | go get -u -d github.com/fananchong/gotcp 12 | go get -u -d github.com/go-yaml/yaml 13 | if [ ! -x "/temp/src/gopkg.in" ]; then 14 | mkdir -p "/temp/src/gopkg.in" 15 | fi 16 | mv -f /temp/src/github.com/go-yaml/yaml /temp/src/gopkg.in/yaml.v2 17 | go get -u -d -insecure github.com/fananchong/multiconfig 18 | go get -u -d github.com/gogo/protobuf/proto 19 | go get -u -d github.com/fananchong/go-redis-orm.v2 20 | go get -u -d github.com/gomodule/redigo/redis 21 | go get -u -d github.com/satori/go.uuid 22 | go get -u -d github.com/fananchong/gochart 23 | go get -u -d github.com/FZambia/sentinel 24 | go get -u -d github.com/bitly/go-simplejson 25 | go get -u -d github.com/fananchong/gomap 26 | go get -u -d github.com/fananchong/goredis 27 | go get -u -d github.com/mna/redisc 28 | go get -u -d -insecure golang.org/x/net/... 29 | go get -u -d github.com/ericchiang/k8s 30 | 31 | unset GOPATH 32 | 33 | git config --unset http.proxy 34 | git config --unset https.proxy 35 | -------------------------------------------------------------------------------- /Godeps/make_godep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker run --rm -e GOBIN=/go/bin/ -v "$PWD"/bin:/go/bin/ golang go get -u github.com/tools/godep 4 | 5 | docker build -t godep . 6 | 7 | docker tag godep:latest fananchong/godep:latest 8 | 9 | set +ex 10 | 11 | docker push fananchong/godep:latest 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 范安崇 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-x 2 | 3 | 本库不再维护,请移步:https://github.com/fananchong/go-xserver 4 | 5 | ## 编译 6 | 7 | - Linux 8 | 9 | ```shell 10 | ./build.sh 11 | ``` 12 | 13 | - Windows 14 | 15 | ```shell 16 | build.bat 17 | ``` 18 | 19 | _(build.bat中GOPATH是特殊路径,需要根据自己本地实际路径做修改)_ 20 | 21 | 22 | ## 服务器运行 23 | 24 | - Linux 25 | 26 | 1. 安装 Kubernetes 27 | 2. 执行 ./build.sh 28 | 29 | 30 | - Windows 31 | 32 | 1. 本地安装redis 33 | 2. hosts文件增加 127.0.0.1 redis.go-x 34 | 3. 执行 go-x\\example1_iogame\\bin\\start.bat 35 | 36 | 37 | ## H5Client 测试客户端 38 | 39 | 1. 更新代码 40 | 41 | ```shell 42 | git.exe submodule update --init -- "tools/h5client" 43 | ``` 44 | 45 | 2. 在 go-x\\tools\\h5client 目录下执行 (只需一次) 46 | 47 | ```shell 48 | cnpm install 49 | ``` 50 | 51 | 3. 在 go-x\\tools\\h5client 目录下执行 52 | 53 | ```shell 54 | run.bat 55 | ``` 56 | 57 | 4. 登录界面服务器 IP 、 Port 58 | 59 | - Windows 60 | 61 | 127.0.0.1 8080 62 | 63 | - Linux 64 | 65 | 你服务器IP 30100 66 | 67 | 68 | 69 | ## 完成的功能 70 | 71 | - Login 服务器 72 | 73 | - 帐号验证、登录 74 | 75 | 76 | - Gateway 服务器 77 | 78 | - 消息中继 79 | 80 | 81 | - Hub 服务器 82 | 83 | - 服务器组内消息广播 84 | 85 | 86 | - Lobby 服务器 87 | 88 | - 创建角色信息 89 | - 查询角色信息 90 | 91 | 92 | ## 支持 kubernetes 部署 93 | 94 | - Linux 完整支持 kubernetes 部署 95 | - Windows 仅做单节点开发调试用 96 | 97 | ## TODO 98 | 99 | - example1_iogame 从 go-x 中分离, go-x 将作为 example1_iogame 的 第三方库方式来使用 100 | 101 | - Hub 重命名为 Center 102 | 103 | - 实现 Gateway 的 session affinity 处理 104 | 105 | - 实现 Lobby 的 session affinity 处理 106 | 107 | - 实现连接管理服务,使之可以不依赖 K8S ,来服务发现 108 | 109 | - match匹配逻辑 110 | 111 | - room实现一个简单的场景 112 | 113 | - 其他 114 | 115 | - session发送缓冲区[]byte不必频繁创建(gotcp优化) 116 | - 增加服务器间相互ping操作 117 | - 待续 118 | -------------------------------------------------------------------------------- /assets/config.toml: -------------------------------------------------------------------------------- 1 | [common] 2 | Version = "0.0.1" 3 | LogDir = "./logs" 4 | LogLevel = 0 5 | Debug = true 6 | IntranetToken = "6d8f1f3a-739f-47fe-9ed1-ea39276cd10d" 7 | MsgCmdOffset = 1000 8 | 9 | [dbaccount] 10 | Name = "account" 11 | Addrs = ["redis.go-x:32000"] 12 | Password = "" 13 | DBIndex = 0 14 | 15 | [dbtoken] 16 | Name = "token" 17 | Addrs = ["redis.go-x:32000"] 18 | Password = "" 19 | DBIndex = 0 20 | 21 | [dbserver] 22 | Name = "server" 23 | Addrs = ["redis.go-x:32000"] 24 | Password = "" 25 | DBIndex = 0 26 | 27 | [login] 28 | Listen = ":8080" 29 | Sign1 = "5UY6$f$h" 30 | Sign2 = "3wokZB%q" 31 | Sign3 = "%2Fi9TRf" 32 | 33 | [gateway] 34 | Connect = [3, 10] #1: login; 2: gateway; 3: hub; 10: lobby; 11: room 35 | 36 | [hub] 37 | 38 | [lobby] 39 | 40 | [room] 41 | -------------------------------------------------------------------------------- /assets/ip.toml: -------------------------------------------------------------------------------- 1 | # 内网IP 到 外网IP 映射表 2 | # 条目格式 [ "内网IP", "外网IP" ] 3 | 4 | data = [ 5 | ["172.19.11.210", "101.132.47.70"], 6 | ] 7 | -------------------------------------------------------------------------------- /assets/server_type.toml: -------------------------------------------------------------------------------- 1 | # 服务名及命名空间 2 | # 请与 go-x/k8s/ 目录中编排脚本中的服务名、命名空间名 保持一致 3 | 4 | [[ServerType]] 5 | Type = 1 6 | Name = "login" 7 | Namespace = "go-x" 8 | 9 | [[ServerType]] 10 | Type = 2 11 | Name = "gateway" 12 | Namespace = "go-x" 13 | 14 | [[ServerType]] 15 | Type = 3 16 | Name = "hub" 17 | Namespace = "go-x" 18 | 19 | [[ServerType]] 20 | Type = 10 21 | Name = "lobby" 22 | Namespace = "go-x" 23 | 24 | [[ServerType]] 25 | Type = 11 26 | Name = "room" 27 | Namespace = "go-x" 28 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | set MYROOT=%~dp0 2 | 3 | cd %MYROOT% 4 | cd common_services 5 | call build.bat 6 | 7 | cd %MYROOT% 8 | cd example1_iogame 9 | call build.bat 10 | 11 | cd %MYROOT% 12 | cd test\test_packet_loss 13 | call build.bat 14 | 15 | cd %MYROOT% 16 | 17 | pause -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | rm -rf ./bin 6 | docker run --rm -e GOBIN=/go/bin/ -v "$PWD"/bin:/go/bin/ -v "$PWD":/go/src/github.com/fananchong/go-x -w /go/src/github.com/fananchong/go-x/common_services golang go install ./... 7 | docker run --rm -e GOBIN=/go/bin/ -v "$PWD"/bin:/go/bin/ -v "$PWD":/go/src/github.com/fananchong/go-x -w /go/src/github.com/fananchong/go-x/example1_iogame golang go install ./... 8 | 9 | docker build -t go-x . 10 | 11 | docker tag go-x:latest 127.0.0.1:5000/fananchong/go-x:latest 12 | 13 | set +ex 14 | 15 | docker push 127.0.0.1:5000/fananchong/go-x:latest 16 | 17 | 18 | kubectl apply -f k8s/namespace.yaml 19 | kubectl apply -f k8s/service_account.yaml 20 | 21 | kubectl delete -f k8s/redis.yaml 22 | kubectl delete -f k8s/login.yaml 23 | kubectl delete -f k8s/gateway.yaml 24 | kubectl delete -f k8s/hub.yaml 25 | kubectl delete -f k8s/lobby.yaml 26 | kubectl delete -f k8s/room.yaml 27 | 28 | kubectl create -f k8s/redis.yaml 29 | kubectl create -f k8s/login.yaml 30 | kubectl create -f k8s/gateway.yaml 31 | kubectl create -f k8s/hub.yaml 32 | kubectl create -f k8s/lobby.yaml 33 | kubectl create -f k8s/room.yaml 34 | -------------------------------------------------------------------------------- /common/args.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | type ArgsBase struct { 4 | Common ArgsCommon // 一些基础参数 5 | Pending ArgsPending // 悬而未决的配置,OnInit()函数内用户最终设置。不同的节点会有针对性的设置。 6 | DbAccount ArgsRedis // 帐号数据库(Redis) 7 | DbToken ArgsRedis // Token数据库(Redis) 8 | DbServer ArgsRedis // Server数据库(Redis) 9 | } 10 | 11 | type ArgsCommon struct { 12 | Version string `default:""` // 版本号 13 | LogDir string `default:""` // log路径 14 | LogLevel int `default:2` // log等级 15 | Debug bool `default:0` // debug版本标志 16 | IntranetToken string `default:""` // 内部服务器验证TOKEN 17 | MsgCmdOffset int `default:100` // 消息号 = 服务类型 * MsgCmdOffset + 数字 18 | } 19 | 20 | type ArgsPending struct { 21 | WatchNodeTypes []int `default:""` // 本节点要watch其他节点的节点类型 22 | } 23 | 24 | type ArgsRedis struct { 25 | Name string `default:""` 26 | Addrs []string `default:""` 27 | Password string `default:""` 28 | DBIndex int `default:0` 29 | } 30 | -------------------------------------------------------------------------------- /common/args_detail.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "path/filepath" 8 | 9 | "github.com/fananchong/multiconfig" 10 | ) 11 | 12 | type IArgs interface { 13 | IArgsBase 14 | OnInit() 15 | } 16 | 17 | type IArgsBase interface { 18 | GetBase() *ArgsBase 19 | Init(derived IArgs) 20 | } 21 | 22 | var ( 23 | _ = flag.String("assets", "", "path of assets") 24 | assetsPath string 25 | ) 26 | 27 | func (this *ArgsBase) Init(derived IArgs) { 28 | index := 0 29 | for i, v := range os.Args { 30 | if v == "-assets" || v == "--assets" { 31 | index = i + 1 32 | } 33 | if v == "-h" || v == "-help" || v == "--help" || v == "/?" { 34 | fl := &multiconfig.FlagLoader{} 35 | fl.Load(derived) 36 | flag.CommandLine.PrintDefaults() 37 | os.Exit(0) 38 | } 39 | } 40 | assetsPath = "" 41 | if index != 0 && index < len(os.Args) { 42 | assetsPath = os.Args[index] + "/" 43 | } 44 | if assetsPath == "" { 45 | assetsPath = "./" 46 | } 47 | dir, err := filepath.Abs(filepath.Dir(assetsPath)) 48 | if err != nil { 49 | fmt.Println("no find assets path, path: " + assetsPath) 50 | } 51 | fmt.Println("Assets Path:", dir) 52 | assetsPath = dir + "/" 53 | cfg := assetsPath + "config.toml" 54 | _, err = os.Stat(cfg) 55 | if !(err == nil || os.IsExist(err)) { 56 | fmt.Println("no find config.toml " + cfg) 57 | } 58 | m := multiconfig.NewWithPath(cfg) 59 | m.MustLoad(derived) 60 | } 61 | 62 | func (this *ArgsBase) GetBase() *ArgsBase { 63 | return this 64 | } 65 | 66 | var xargs *ArgsBase 67 | 68 | func SetArgs(args *ArgsBase) { 69 | xargs = args 70 | } 71 | 72 | func GetArgs() *ArgsBase { 73 | return xargs 74 | } 75 | 76 | func GetAssetsPath() string { 77 | return assetsPath 78 | } 79 | -------------------------------------------------------------------------------- /common/init.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | func init() { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /common/k8s/endpoint.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | const ID_BASE = 100000 4 | 5 | type Endpoint struct { 6 | NodeType int 7 | Index int 8 | IP string 9 | Ports map[string]int 10 | } 11 | 12 | func NewEndpoint() *Endpoint { 13 | return &Endpoint{ 14 | Ports: make(map[string]int), 15 | } 16 | } 17 | 18 | func (this *Endpoint) Id() uint32 { 19 | return uint32(this.NodeType*ID_BASE + this.Index) 20 | } 21 | -------------------------------------------------------------------------------- /common/k8s/k8s_api_linux.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | import ( 4 | "context" 5 | "strconv" 6 | 7 | "github.com/ericchiang/k8s" 8 | corev1 "github.com/ericchiang/k8s/apis/core/v1" 9 | ) 10 | 11 | func GetEndpoints(namespace, service string) ([]*Endpoint, error) { 12 | client, err := k8s.NewInClusterClient() 13 | if err != nil { 14 | return nil, err 15 | } 16 | 17 | var ips []*Endpoint 18 | var endpoints corev1.Endpoints 19 | err = client.Get(context.Background(), namespace, service, &endpoints) 20 | if err != nil { 21 | return nil, err 22 | } 23 | 24 | for _, endpoint := range endpoints.Subsets { 25 | for _, address := range endpoint.Addresses { 26 | index := getIndex(service, *address.Hostname) 27 | item := NewEndpoint() 28 | item.IP = *address.Ip 29 | item.Index = index 30 | for _, port := range endpoint.Ports { 31 | item.Ports[*port.Name] = int(*port.Port) + index 32 | } 33 | ips = append(ips, item) 34 | } 35 | } 36 | 37 | return ips, nil 38 | } 39 | 40 | func getIndex(service string, name string) int { 41 | if len(service) >= len(name) { 42 | return 0 43 | } 44 | id, err := strconv.Atoi(name[len(service)+1:]) 45 | if err != nil { 46 | return 0 47 | } 48 | return id 49 | } 50 | -------------------------------------------------------------------------------- /common/k8s/k8s_api_windows.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | func GetEndpoints(namespace, service string) ([]*Endpoint, error) { 4 | item := NewEndpoint() 5 | item.Index = 0 6 | item.IP = "localhost" 7 | 8 | var ips []*Endpoint 9 | t := GetServiceType(namespace, service) 10 | if t > 0 { 11 | 12 | item.NodeType = t 13 | item.Ports[""] = 30000 + t*100 14 | ips = append(ips, item) 15 | return ips, nil 16 | } 17 | return ips, nil 18 | } 19 | 20 | func getIndex(service string, name string) int { 21 | return 0 22 | } 23 | -------------------------------------------------------------------------------- /common/k8s/node.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "os" 7 | "time" 8 | ) 9 | 10 | type INode interface { 11 | OnNodeJoin(endpoint *Endpoint) 12 | OnNodeLeave(endpoint *Endpoint) 13 | GetBase() interface{} 14 | } 15 | 16 | type Node struct { 17 | endpoint *Endpoint 18 | ctx context.Context 19 | ctxCancel context.CancelFunc 20 | watchs []*Watch 21 | } 22 | 23 | func (this *Node) Init(nodeType int, watchNodeTypes []int, d time.Duration, inst INode) error { 24 | if nt, ok := gNodeTypes[nodeType]; ok { 25 | this.ctx, this.ctxCancel = context.WithCancel(context.Background()) 26 | index := getIndex(nt.svc, os.Getenv("POD_NAME")) 27 | LABEL_GETEP: 28 | if eps, err := GetEndpoints(nt.ns, nt.svc); err == nil { 29 | for _, ep := range eps { 30 | ep.NodeType = nt.t 31 | if index == ep.Index { 32 | this.endpoint = ep 33 | break 34 | } 35 | } 36 | if this.endpoint == nil { 37 | time.Sleep(1 * time.Second) 38 | goto LABEL_GETEP 39 | } 40 | for _, v := range watchNodeTypes { 41 | if v_nt, ok := gNodeTypes[v]; ok { 42 | w := NewWatch(v_nt, this.ctx, d, inst) 43 | this.watchs = append(this.watchs, w) 44 | } 45 | } 46 | return nil 47 | } else { 48 | return err 49 | } 50 | } else { 51 | return errors.New("no find nodeType info!") 52 | } 53 | } 54 | 55 | func (this *Node) Close() { 56 | if this.ctxCancel != nil { 57 | this.ctxCancel() 58 | this.ctxCancel = nil 59 | } 60 | } 61 | 62 | func (this *Node) Id() uint32 { 63 | return this.endpoint.Id() 64 | } 65 | 66 | func (this *Node) Ports(name string) int { 67 | return this.endpoint.Ports[name] 68 | } 69 | 70 | func (this *Node) GetBase() interface{} { 71 | return this 72 | } 73 | 74 | // 子类可以根据需要重载下面的方法 75 | // 注意 OnNodeJoin 、 OnNodeLeave 在内部协程被调用,请注意多协程安全!!! 76 | func (this *Node) OnNodeJoin(endpoint *Endpoint) { 77 | 78 | } 79 | 80 | func (this *Node) OnNodeLeave(endpoint *Endpoint) { 81 | for _, v := range this.watchs { 82 | if v.nt.t == endpoint.NodeType { 83 | v.OnLoseEndpoint(endpoint.Index) 84 | break 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /common/k8s/node_type.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | type NodeType struct { 4 | t int 5 | ns string 6 | svc string 7 | } 8 | 9 | var gNodeTypes map[int]*NodeType = make(map[int]*NodeType) 10 | 11 | func RegisterNodeType(t int, ns, svc string) { 12 | nt := &NodeType{ 13 | t: t, 14 | ns: ns, 15 | svc: svc, 16 | } 17 | gNodeTypes[t] = nt 18 | } 19 | 20 | func GetNamespace(t int) string { 21 | if v, ok := gNodeTypes[t]; ok { 22 | return v.ns 23 | } 24 | return "" 25 | } 26 | 27 | func GetServiceName(t int) string { 28 | if v, ok := gNodeTypes[t]; ok { 29 | return v.svc 30 | } 31 | return "" 32 | } 33 | 34 | // 给 k8s_api_windows.go 使用,不需要考虑效率问题 35 | func GetServiceType(ns, svc string) int { 36 | for k, v := range gNodeTypes { 37 | if v.ns == ns && v.svc == svc { 38 | return k 39 | } 40 | } 41 | return 0 42 | } 43 | -------------------------------------------------------------------------------- /common/k8s/serverlist/node.go: -------------------------------------------------------------------------------- 1 | package discovery 2 | 3 | import ( 4 | "sync" 5 | "time" 6 | 7 | "github.com/fananchong/go-x/common/k8s" 8 | ) 9 | 10 | type Node struct { 11 | k8s.Node 12 | Servers IServers 13 | mutex sync.RWMutex 14 | } 15 | 16 | func NewNode() *Node { 17 | this := &Node{} 18 | this.Servers = NewServersPolicyRoundRobin() 19 | return this 20 | } 21 | 22 | func (this *Node) Init(nodeType int, watchNodeTypes []int, d time.Duration, inst k8s.INode) error { 23 | SetNode(this) 24 | return this.Node.Init(nodeType, watchNodeTypes, d, inst) 25 | } 26 | 27 | func (this *Node) OnNodeJoin(endpoint *k8s.Endpoint) { 28 | this.Servers.Set(endpoint.NodeType, endpoint.Id(), endpoint) 29 | } 30 | 31 | func (this *Node) OnNodeLeave(endpoint *k8s.Endpoint) { 32 | this.Servers.Delete(endpoint.NodeType, endpoint.Id()) 33 | this.Node.OnNodeLeave(endpoint) 34 | } 35 | 36 | /// ================================================== 37 | 38 | func (this *Node) GetBase() interface{} { 39 | return this 40 | } 41 | 42 | var xnode *Node 43 | 44 | func SetNode(node *Node) { 45 | xnode = node 46 | } 47 | 48 | func GetNode() *Node { 49 | return xnode 50 | } 51 | -------------------------------------------------------------------------------- /common/k8s/watch.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "sync" 7 | "time" 8 | ) 9 | 10 | type Watch struct { 11 | nt *NodeType 12 | endpoints sync.Map 13 | ctx context.Context 14 | ctxCancel context.CancelFunc 15 | tick *time.Ticker 16 | derived INode 17 | } 18 | 19 | func NewWatch(nt *NodeType, ctx context.Context, d time.Duration, derived INode) *Watch { 20 | this := &Watch{ 21 | nt: nt, 22 | derived: derived, 23 | } 24 | this.init(ctx, d) 25 | return this 26 | } 27 | 28 | func (this *Watch) init(ctx context.Context, d time.Duration) { 29 | this.ctx, this.ctxCancel = context.WithCancel(ctx) 30 | this.tick = time.NewTicker(d) 31 | go func() { 32 | for { 33 | select { 34 | case <-this.tick.C: 35 | this.checkEndpoints() 36 | case <-this.ctx.Done(): 37 | this.close() 38 | return 39 | } 40 | } 41 | }() 42 | } 43 | 44 | func (this *Watch) checkEndpoints() { 45 | if eps, err := GetEndpoints(this.nt.ns, this.nt.svc); err == nil { 46 | for _, ep := range eps { 47 | if _, ok := this.endpoints.Load(ep.Index); !ok { 48 | ep.NodeType = this.nt.t 49 | this.endpoints.Store(ep.Index, ep) 50 | this.derived.OnNodeJoin(ep) 51 | } 52 | } 53 | } else { 54 | fmt.Errorf("%v\n", err) 55 | } 56 | } 57 | 58 | func (this *Watch) close() { 59 | if this.tick != nil { 60 | this.tick.Stop() 61 | this.tick = nil 62 | } 63 | } 64 | 65 | func (this *Watch) OnLoseEndpoint(index int) { 66 | this.endpoints.Delete(index) 67 | } 68 | -------------------------------------------------------------------------------- /common/service_def.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common/k8s" 5 | "github.com/fananchong/multiconfig" 6 | ) 7 | 8 | type CommonServerType int 9 | 10 | const ( 11 | Client CommonServerType = iota // 0 12 | Login // 1 13 | Gateway // 2 14 | Hub // 3 15 | COMMON_SERVER_END = 9 // 9 16 | ) 17 | 18 | type ServerTypeConfig struct { 19 | ServerType []ServerTypeInfo 20 | } 21 | 22 | type ServerTypeInfo struct { 23 | Type int 24 | Name string 25 | Namespace string 26 | } 27 | 28 | func initServerType() { 29 | path := GetAssetsPath() + "server_type.toml" 30 | cfg := &ServerTypeConfig{} 31 | m := &multiconfig.TOMLLoader{ 32 | Path: path, 33 | } 34 | err := m.Load(cfg) 35 | if err != nil { 36 | panic(err) 37 | } 38 | for _, v := range cfg.ServerType { 39 | k8s.RegisterNodeType(v.Type, v.Namespace, v.Name) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /common/tcp.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | 6 | discovery "github.com/fananchong/go-x/common/k8s/serverlist" 7 | "github.com/fananchong/gotcp" 8 | ) 9 | 10 | type TcpServer struct { 11 | *gotcp.Server 12 | } 13 | 14 | func NewTcpServer() *TcpServer { 15 | this := &TcpServer{ 16 | Server: &gotcp.Server{}, 17 | } 18 | return this 19 | } 20 | 21 | func (this *TcpServer) Start() bool { 22 | gotcp.SetLogger(xlog) 23 | if this.startServer() == false { 24 | return false 25 | } 26 | return true 27 | } 28 | 29 | func (this *TcpServer) startServer() bool { 30 | port := discovery.GetNode().Ports("") 31 | return this.Server.Start(fmt.Sprintf(":%d", port)) 32 | } 33 | 34 | func (this *TcpServer) Close() { 35 | this.Server.Close() 36 | } 37 | -------------------------------------------------------------------------------- /common/web.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "net/http" 5 | "time" 6 | ) 7 | 8 | type WebService struct { 9 | server *http.Server 10 | serverMux *http.ServeMux 11 | termination bool 12 | } 13 | 14 | func NewWebService() *WebService { 15 | return &WebService{serverMux: http.NewServeMux()} 16 | } 17 | 18 | func (this *WebService) ListenAndServe(addr string) { 19 | xlog.Infoln("start listen", addr) 20 | this.termination = false 21 | for !this.termination { 22 | this.server = &http.Server{Addr: addr, Handler: this.serverMux} 23 | err := this.server.ListenAndServe() 24 | if err != nil { 25 | xlog.Errorln("[web]", err) 26 | if this.server != nil { 27 | this.server.Close() 28 | } 29 | time.Sleep(5 * time.Second) 30 | } 31 | } 32 | } 33 | 34 | func (this *WebService) Close() { 35 | this.termination = true 36 | if this.server != nil { 37 | this.server.Close() 38 | this.server = nil 39 | } 40 | } 41 | 42 | func (this *WebService) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { 43 | if this.serverMux == nil { 44 | this.serverMux = http.NewServeMux() 45 | } 46 | this.serverMux.HandleFunc(pattern, handler) 47 | } 48 | -------------------------------------------------------------------------------- /common_services/bin/start.bat.sample: -------------------------------------------------------------------------------- 1 | set MYDIR=%~dp0 2 | 3 | call stop.bat 4 | 5 | cd .. 6 | call build.bat 7 | 8 | cd %MYDIR% 9 | 10 | start login.exe -assets ..\..\assets -common-loglevel 0 11 | ping -n 3 127.0.0.1>nul 12 | start gateway.exe -assets ..\..\assets -common-loglevel 0 13 | ping -n 3 127.0.0.1>nul 14 | start hub.exe -assets ..\..\assets -common-loglevel 0 15 | ping -n 3 127.0.0.1>nul 16 | -------------------------------------------------------------------------------- /common_services/bin/stop.bat: -------------------------------------------------------------------------------- 1 | taskkill /F /IM login.exe 2 | taskkill /F /IM gateway.exe 3 | taskkill /F /IM hub.exe 4 | -------------------------------------------------------------------------------- /common_services/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR%\..\..\..\..\..\ 3 | set GOPATH=%BASEDIR%;%CURDIR% 4 | set GOBIN=%CURDIR%\bin 5 | go install -race ./... 6 | -------------------------------------------------------------------------------- /common_services/db/UID.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | go_redis_orm "github.com/fananchong/go-redis-orm.v2" 5 | "github.com/gomodule/redigo/redis" 6 | ) 7 | 8 | const ( 9 | SUID_TYPE_ACCOUNT = "account" 10 | ) 11 | 12 | // Server Unique Identifier 13 | type SUID struct { 14 | Cli go_redis_orm.IClient 15 | } 16 | 17 | func (this *SUID) New(typ string) (uint64, error) { 18 | return redis.Uint64(this.Cli.Do("HINCRBY", "suid", typ, 1)) 19 | } 20 | -------------------------------------------------------------------------------- /common_services/db/g.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | docker run --rm -v "$PWD"/redis_def:/app/input -v "$PWD":/app/output fananchong/redis2go --package=db 6 | 7 | -------------------------------------------------------------------------------- /common_services/db/redis_def/account.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Account", 3 | "type": "1-1", 4 | "key": "string", 5 | "fields": { 6 | "uid": "uint64", 7 | "pswd": "string" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /common_services/db/redis_def/token.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Token", 3 | "type": "1-1", 4 | "key": "string", 5 | "fields": { 6 | "uid": "uint64", 7 | "token": "string" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /common_services/db/redis_def/uidserver.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UIDServer", 3 | "type": "1-1", 4 | "key": "uint64", 5 | "fields": { 6 | "gateway": "uint32" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /common_services/gateway/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-redis-orm.v2" 5 | "github.com/fananchong/go-x/common" 6 | ) 7 | 8 | var ( 9 | xargs *Args = &Args{} 10 | xlog common.ILogger = common.NewGLogger() 11 | xnode *Node = NewNode() 12 | ) 13 | 14 | type App struct { 15 | common.App 16 | } 17 | 18 | func NewApp() *App { 19 | this := &App{} 20 | this.Type = int(common.Gateway) 21 | this.Args = xargs 22 | this.Logger = xlog 23 | this.Node = xnode 24 | this.Derived = this 25 | return this 26 | } 27 | 28 | var runner = common.NewTcpServer() 29 | 30 | func (this *App) OnAppReady() { 31 | if initRedis() == false { 32 | this.Close() 33 | return 34 | } 35 | go func() { 36 | runner.RegisterSessType(SessionAccount{}) 37 | if runner.Start() == false { 38 | this.Close() 39 | } 40 | }() 41 | } 42 | 43 | func (this *App) OnAppShutDown() { 44 | runner.Close() 45 | } 46 | 47 | func initRedis() bool { 48 | go_redis_orm.SetNewRedisHandler(go_redis_orm.NewDefaultRedisClient) 49 | err := go_redis_orm.CreateDB( 50 | common.GetArgs().DbToken.Name, 51 | common.GetArgs().DbToken.Addrs, 52 | common.GetArgs().DbToken.Password, 53 | common.GetArgs().DbToken.DBIndex) 54 | if err != nil { 55 | common.GetLogger().Errorln(err) 56 | return false 57 | } 58 | err = go_redis_orm.CreateDB( 59 | common.GetArgs().DbServer.Name, 60 | common.GetArgs().DbServer.Addrs, 61 | common.GetArgs().DbServer.Password, 62 | common.GetArgs().DbServer.DBIndex) 63 | if err != nil { 64 | common.GetLogger().Errorln(err) 65 | return false 66 | } 67 | return true 68 | } 69 | -------------------------------------------------------------------------------- /common_services/gateway/args.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | type Args struct { 8 | common.ArgsBase 9 | Gateway ArgsGateway 10 | } 11 | 12 | type ArgsGateway struct { 13 | Connect []int 14 | } 15 | 16 | func (this *Args) OnInit() { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /common_services/gateway/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | app := NewApp() 5 | app.Run() 6 | } 7 | -------------------------------------------------------------------------------- /common_services/hub/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | var ( 8 | xargs *Args = &Args{} 9 | xlog common.ILogger = common.NewGLogger() 10 | ) 11 | 12 | type App struct { 13 | common.App 14 | } 15 | 16 | func NewApp() *App { 17 | this := &App{} 18 | this.Type = int(common.Hub) 19 | this.Args = xargs 20 | this.Logger = xlog 21 | this.Derived = this 22 | return this 23 | } 24 | 25 | var runner = common.NewTcpServer() 26 | 27 | func (this *App) OnAppReady() { 28 | go func() { 29 | runner.RegisterSessType(SessionNode{}) 30 | if runner.Start() == false { 31 | this.Close() 32 | } 33 | }() 34 | } 35 | 36 | func (this *App) OnAppShutDown() { 37 | runner.Close() 38 | } 39 | -------------------------------------------------------------------------------- /common_services/hub/args.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | type Args struct { 8 | common.ArgsBase 9 | Hub ArgsHub 10 | } 11 | 12 | type ArgsHub struct { 13 | } 14 | 15 | func (this *Args) OnInit() { 16 | } 17 | -------------------------------------------------------------------------------- /common_services/hub/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | app := NewApp() 5 | app.Run() 6 | } 7 | -------------------------------------------------------------------------------- /common_services/hub/session_node.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "net" 6 | 7 | service "github.com/fananchong/go-x/common_services" 8 | "github.com/fananchong/gotcp" 9 | ) 10 | 11 | type SessionNode struct { 12 | service.SessionIntranet 13 | } 14 | 15 | func (this *SessionNode) Init(conn net.Conn, root context.Context, derived gotcp.ISession) { 16 | this.SessionIntranet.Init(conn, root, derived) 17 | 18 | // init cmd 19 | this.DefaultHandler = this.cmdDefault 20 | } 21 | 22 | func (this *SessionNode) cmdDefault(_ uint64, data []byte, flag byte) { 23 | this.BroadcastExcludeMe(data, flag) 24 | } 25 | -------------------------------------------------------------------------------- /common_services/init.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import "github.com/fananchong/go-x/common" 4 | 5 | func init() { 6 | LoadIpConfig(common.GetAssetsPath() + "ip.toml") 7 | } 8 | 9 | -------------------------------------------------------------------------------- /common_services/ip.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import "github.com/fananchong/multiconfig" 4 | 5 | type IpConfig struct { 6 | Data [][2]string 7 | } 8 | 9 | var gIP map[string]string = make(map[string]string) 10 | 11 | func LoadIpConfig(path string) error { 12 | cfg := &IpConfig{} 13 | m := &multiconfig.TOMLLoader{ 14 | Path: path, 15 | } 16 | err := m.Load(cfg) 17 | if err != nil { 18 | return err 19 | } 20 | for _, v := range cfg.Data { 21 | gIP[v[0]] = v[1] 22 | } 23 | return nil 24 | } 25 | 26 | func GetIpList() *map[string]string { 27 | return &gIP 28 | } 29 | 30 | -------------------------------------------------------------------------------- /common_services/ip_test.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_IpConfig(t *testing.T) { 8 | err := LoadIpConfig("../assets/ip.toml") 9 | if err == nil { 10 | t.Log(gIP) 11 | } else { 12 | t.Error(err) 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /common_services/login/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | var ( 8 | xargs *Args = &Args{} 9 | xlog common.ILogger = common.NewGLogger() 10 | ) 11 | 12 | type App struct { 13 | common.App 14 | } 15 | 16 | func NewApp() *App { 17 | this := &App{} 18 | this.Type = int(common.Login) 19 | this.Args = xargs 20 | this.Logger = xlog 21 | this.Derived = this 22 | return this 23 | } 24 | 25 | var runner = NewLogin() 26 | 27 | func (this *App) OnAppReady() { 28 | go func() { 29 | if runner.Start() == false { 30 | this.Close() 31 | } 32 | }() 33 | } 34 | 35 | func (this *App) OnAppShutDown() { 36 | runner.Close() 37 | } 38 | -------------------------------------------------------------------------------- /common_services/login/args.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | type Args struct { 8 | common.ArgsBase 9 | Login ArgsLogin // 登录服务配置 10 | } 11 | 12 | type ArgsLogin struct { 13 | Listen string `default:":8000"` 14 | Sign1 string `default:""` 15 | Sign2 string `default:""` 16 | Sign3 string `default:""` 17 | } 18 | 19 | func (this *Args) OnInit() { 20 | this.Pending.WatchNodeTypes = append(this.Pending.WatchNodeTypes, int(common.Gateway)) // 监视服务节点类型 21 | } 22 | -------------------------------------------------------------------------------- /common_services/login/login.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | 6 | go_redis_orm "github.com/fananchong/go-redis-orm.v2" 7 | "github.com/fananchong/go-x/common" 8 | "github.com/fananchong/go-x/common_services/db" 9 | "github.com/fananchong/go-x/common_services/proto" 10 | "github.com/fananchong/gotcp" 11 | ) 12 | 13 | type LoginMsgHandlerType func(http.ResponseWriter, *http.Request, string, string) 14 | 15 | type Login struct { 16 | common.WebService 17 | cmds map[proto.MsgTypeCmd]LoginMsgHandlerType 18 | dbAccountName string 19 | dbTokenName string 20 | suid *db.SUID 21 | } 22 | 23 | func NewLogin() *Login { 24 | return &Login{} 25 | } 26 | 27 | func (this *Login) Start() bool { 28 | if this.cmds == nil { 29 | this.cmds = make(map[proto.MsgTypeCmd]LoginMsgHandlerType) 30 | this.cmds[proto.MsgTypeCmd_Login] = this.MsgLogin 31 | } 32 | 33 | go_redis_orm.SetNewRedisHandler(go_redis_orm.NewDefaultRedisClient) 34 | 35 | // db account 36 | this.dbAccountName = common.GetArgs().DbAccount.Name 37 | err := go_redis_orm.CreateDB(this.dbAccountName, common.GetArgs().DbAccount.Addrs, common.GetArgs().DbAccount.Password, common.GetArgs().DbAccount.DBIndex) 38 | if err != nil { 39 | common.GetLogger().Errorln(err) 40 | return false 41 | } 42 | 43 | // db token 44 | this.dbTokenName = common.GetArgs().DbToken.Name 45 | err = go_redis_orm.CreateDB(this.dbTokenName, common.GetArgs().DbToken.Addrs, common.GetArgs().DbToken.Password, common.GetArgs().DbToken.DBIndex) 46 | if err != nil { 47 | common.GetLogger().Errorln(err) 48 | return false 49 | } 50 | 51 | // suid 52 | this.suid = &db.SUID{Cli: go_redis_orm.GetDB(this.dbAccountName)} 53 | 54 | // logger 55 | gotcp.SetLogger(common.GetLogger()) 56 | 57 | // http service 58 | this.HandleFunc("/msg", this.request) 59 | this.ListenAndServe(xargs.Login.Listen) 60 | return true 61 | } 62 | 63 | func (this *Login) Register(cmd proto.MsgTypeCmd, f LoginMsgHandlerType) { 64 | if _, ok := this.cmds[cmd]; !ok { 65 | this.cmds[cmd] = f 66 | } else { 67 | panic("Register fail.") 68 | } 69 | } 70 | 71 | func (this *Login) Close() { 72 | this.WebService.Close() 73 | } 74 | -------------------------------------------------------------------------------- /common_services/login/login_extend.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common_services/proto" 5 | ) 6 | 7 | // 第3方平台,获取帐号密码 8 | func (this *Login) GetPassword(account string, mode proto.LoginMode, userdata []byte) (string, proto.EnumLogin_Error) { 9 | return "", proto.EnumLogin_ErrPlatformSide 10 | } 11 | -------------------------------------------------------------------------------- /common_services/login/login_request.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/md5" 5 | "fmt" 6 | "net/http" 7 | "strconv" 8 | 9 | "github.com/fananchong/go-x/common" 10 | "github.com/fananchong/go-x/common_services/proto" 11 | "github.com/fananchong/gotcp" 12 | proto1 "github.com/golang/protobuf/proto" 13 | ) 14 | 15 | func (this *Login) request(w http.ResponseWriter, req *http.Request) { 16 | req.ParseForm() 17 | paramc, ok1 := req.Form["c"] 18 | paramt, ok2 := req.Form["t"] 19 | paramd, ok3 := req.Form["d"] 20 | params, ok4 := req.Form["s"] 21 | if !ok1 || !ok2 || !ok3 || !ok4 { 22 | common.GetLogger().Debugln("http request param error!") 23 | return 24 | } 25 | c, err := strconv.Atoi(paramc[0]) 26 | if err != nil { 27 | common.GetLogger().Debugln("http request param c error!") 28 | return 29 | } 30 | 31 | s1 := []byte(xargs.Login.Sign1 + paramc[0] + xargs.Login.Sign2 + paramt[0] + xargs.Login.Sign3 + xargs.Common.Version) 32 | s2 := md5.Sum(s1) 33 | s3 := fmt.Sprintf("%x", s2) 34 | 35 | if s3 != params[0] { 36 | common.GetLogger().Debugln("version error!") 37 | common.GetLogger().Debugln(" client sign =", params[0]) 38 | common.GetLogger().Debugln(" server sign =", s3) 39 | common.GetLogger().Debugln(" sign1 =", xargs.Login.Sign1) 40 | common.GetLogger().Debugln(" sign2 =", xargs.Login.Sign2) 41 | common.GetLogger().Debugln(" sign3 =", xargs.Login.Sign3) 42 | common.GetLogger().Debugln(" c =", paramc[0]) 43 | common.GetLogger().Debugln(" t =", paramt[0]) 44 | common.GetLogger().Debugln(" version =", xargs.Common.Version) 45 | 46 | return 47 | } 48 | 49 | if handler, ok := this.cmds[proto.MsgTypeCmd(c)]; ok { 50 | handler(w, req, paramd[0], params[0]) 51 | } else { 52 | common.GetLogger().Debugln("unknow cmd, cmd =", c) 53 | return 54 | } 55 | } 56 | 57 | func (this *Login) decodeMsg(data string, msg proto1.Message) proto1.Message { 58 | return gotcp.DecodeCmdEx([]byte(data), 0, msg, 0) 59 | } 60 | -------------------------------------------------------------------------------- /common_services/login/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | app := NewApp() 5 | app.Run() 6 | } 7 | -------------------------------------------------------------------------------- /common_services/proto/g.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | 6 | 7 | ROOT_DIR=$PWD 8 | docker run --rm -v $ROOT_DIR:$ROOT_DIR -w $ROOT_DIR znly/protoc --gogofaster_out=. -I=. *.proto 9 | 10 | ROOT_DIR=$PWD/../../ 11 | docker run --rm -v $ROOT_DIR:$ROOT_DIR -w $ROOT_DIR znly/protoc --js_out=import_style=commonjs,binary:./tools/h5client/src/app/proto/ -I=./common_services/proto *.proto 12 | 13 | -------------------------------------------------------------------------------- /doc/Gateway 的 session affinity 处理.md: -------------------------------------------------------------------------------- 1 | ## 时序图 2 | 3 | ![Gateway 的 session affinity 处理](Gateway 的 session affinity 处理.svg) 4 | 5 | ## 说明 6 | 7 | - gateway 失效时,可能导致的问题: 8 | 9 | 2.2 步骤中 可能会把 新登陆请求的 SET NX 删除 (概率非常小) 10 | 11 | 因此这里写的命令是 DELX 不是 Redis 原生的 DEL。需要用 redis module 做一个 `DELX` :条件删除, if value = "xxx" then del key (或使用 Redis Lua 脚本) 12 | 13 | - 6 步骤中的 EXPIRE 后,有小概率 可能会把 新登陆请求的 SET NX 删除 14 | 15 | 因此步骤2.1 中写的是 SETX 不是 Redis 原生的 SET。需要用 redis module 做一个 `SETX` : 不管 SET NX 有没有设置成功,都重置过期时间为 1 年 (或使用 Redis Lua 脚本) 16 | -------------------------------------------------------------------------------- /doc/IO服务器架构图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fananchong/go-x/b77c001f2e21461fd78ed2c0b2d7ae6cbb78a605/doc/IO服务器架构图.jpg -------------------------------------------------------------------------------- /doc/Lobby 的 session affinity 处理.md: -------------------------------------------------------------------------------- 1 | ![Lobby 的 session affinity 处理](assets/Lobby 的 session affinity 处理.svg) 2 | -------------------------------------------------------------------------------- /doc/消息号规范.md: -------------------------------------------------------------------------------- 1 | # 消息号规范 2 | 3 | ## 内部消息号 4 | 5 | 范围:1 - 100 6 | 7 | ## 扩展服务消息号 8 | 9 | 消息号 = 服务类型 * 偏移 + 数字 10 | 11 | 目的: 12 | 13 | - 方便消息号归类 14 | - 方便消息投递到 Gateway 后, Gateway 知道转发给哪种类型服务器 15 | 16 | 举例: Lobby 服务类型为 10 ,偏移为 1000,则 Lobby 的消息请定义为: 10001、10002、... 等等 17 | 18 | ## 消息号偏移量定义在配置中 19 | 20 | config.toml 配置文件中的 common.MsgCmdOffset 字段 21 | -------------------------------------------------------------------------------- /doc/登录时序图1-帐号验证段.md: -------------------------------------------------------------------------------- 1 | ![登录时序图1](assets/登录时序图1-帐号验证段.svg) 2 | -------------------------------------------------------------------------------- /doc/登录时序图2-游戏网关段.md: -------------------------------------------------------------------------------- 1 | ![登录时序图2](assets/登录时序图2-游戏网关段.svg) 2 | -------------------------------------------------------------------------------- /example1_iogame/bin/start.bat.sample: -------------------------------------------------------------------------------- 1 | set MYDIR=%~dp0 2 | set COMMONSRVDIR=%~dp0\..\..\common_services 3 | set ASSETSDIR=%~dp0\..\..\assets 4 | 5 | call stop.bat 6 | 7 | cd %COMMONSRVDIR% 8 | call build.bat 9 | 10 | cd %MYDIR%\.. 11 | call build.bat 12 | 13 | cd %MYDIR% 14 | 15 | 16 | start lobby.exe -assets ..\..\assets -common-loglevel 0 17 | ping -n 3 127.0.0.1>nul 18 | start room.exe -assets ..\..\assets -common-loglevel 0 19 | ping -n 3 127.0.0.1>nul 20 | 21 | 22 | start %COMMONSRVDIR%\bin\login.exe -assets ..\..\assets -common-loglevel 0 23 | ping -n 3 127.0.0.1>nul 24 | start %COMMONSRVDIR%\bin\gateway.exe -assets ..\..\assets -common-loglevel 0 25 | ping -n 3 127.0.0.1>nul 26 | start %COMMONSRVDIR%\bin\hub.exe -assets ..\..\assets -common-loglevel 0 27 | ping -n 3 127.0.0.1>nul 28 | -------------------------------------------------------------------------------- /example1_iogame/bin/stop.bat: -------------------------------------------------------------------------------- 1 | taskkill /F /IM login.exe 2 | taskkill /F /IM gateway.exe 3 | taskkill /F /IM lobby.exe 4 | taskkill /F /IM room.exe 5 | taskkill /F /IM hub.exe -------------------------------------------------------------------------------- /example1_iogame/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR%\..\..\..\..\..\ 3 | set GOPATH=%BASEDIR%;%CURDIR% 4 | set GOBIN=%CURDIR%\bin 5 | go install -race ./... 6 | -------------------------------------------------------------------------------- /example1_iogame/db/g.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | docker run --rm -v "$PWD"/redis_def:/app/input -v "$PWD":/app/output fananchong/redis2go --package=db 6 | 7 | -------------------------------------------------------------------------------- /example1_iogame/db/redis_def/role.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Role", 3 | "type": "1-1", 4 | "key": "uint64", 5 | "fields": { 6 | "name": "string", 7 | "sex": "uint8" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example1_iogame/lobby/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-redis-orm.v2" 5 | "github.com/fananchong/go-x/common" 6 | "github.com/fananchong/go-x/example1_iogame" 7 | ) 8 | 9 | var ( 10 | xargs *Args = &Args{} 11 | xlog common.ILogger = common.NewGLogger() 12 | ) 13 | 14 | type App struct { 15 | common.App 16 | } 17 | 18 | func NewApp() *App { 19 | this := &App{} 20 | this.Type = int(iogame.Lobby) 21 | this.Args = xargs 22 | this.Logger = xlog 23 | this.Derived = this 24 | return this 25 | } 26 | 27 | var runner = common.NewTcpServer() 28 | 29 | func (this *App) OnAppReady() { 30 | if initRedis() == false { 31 | this.Close() 32 | return 33 | } 34 | go func() { 35 | runner.RegisterSessType(SessionNode{}) 36 | if runner.Start() == false { 37 | this.Close() 38 | } 39 | }() 40 | } 41 | 42 | func (this *App) OnAppShutDown() { 43 | runner.Close() 44 | } 45 | 46 | func initRedis() bool { 47 | go_redis_orm.SetNewRedisHandler(go_redis_orm.NewDefaultRedisClient) 48 | err := go_redis_orm.CreateDB( 49 | common.GetArgs().DbAccount.Name, 50 | common.GetArgs().DbAccount.Addrs, 51 | common.GetArgs().DbAccount.Password, 52 | common.GetArgs().DbAccount.DBIndex) 53 | if err != nil { 54 | common.GetLogger().Errorln(err) 55 | return false 56 | } 57 | return true 58 | } 59 | -------------------------------------------------------------------------------- /example1_iogame/lobby/args.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | var DbAccount string 8 | 9 | type Args struct { 10 | common.ArgsBase 11 | Lobby ArgsLobby 12 | } 13 | 14 | type ArgsLobby struct { 15 | } 16 | 17 | func (this *Args) OnInit() { 18 | DbAccount = this.ArgsBase.DbAccount.Name 19 | } 20 | -------------------------------------------------------------------------------- /example1_iogame/lobby/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | app := NewApp() 5 | app.Run() 6 | } 7 | -------------------------------------------------------------------------------- /example1_iogame/proto/g.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | 6 | 7 | ROOT_DIR=$PWD 8 | docker run --rm -v $ROOT_DIR:$ROOT_DIR -w $ROOT_DIR znly/protoc --gogofaster_out=. -I=. *.proto 9 | 10 | ROOT_DIR=$PWD/../../ 11 | docker run --rm -v $ROOT_DIR:$ROOT_DIR -w $ROOT_DIR znly/protoc --js_out=import_style=commonjs,binary:./tools/h5client/src/app/proto/ -I=./example1_iogame/proto *.proto 12 | 13 | -------------------------------------------------------------------------------- /example1_iogame/proto/lobby.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package proto; 4 | 5 | enum MsgTypeCmd_Lobby { 6 | UNSPECIFIED = 0; 7 | CreatePlayer = 10001; // 创建角色 8 | PlayerBaseInfo = 10002; // 角色基本信息 9 | }; 10 | 11 | 12 | /// CreatePlayer 13 | 14 | message EnumCreatePlayer 15 | { 16 | enum Error { 17 | NoErr = 0; 18 | ErrDB = 1; // 数据库错误 19 | ErrExist = 2; // 已经存在 20 | } 21 | } 22 | 23 | message MsgCreatePlayer 24 | { 25 | string Name = 1; // 角色名字 26 | int32 Sex = 2; // 角色性别 27 | } 28 | 29 | message MsgCreatePlayerResult 30 | { 31 | EnumCreatePlayer.Error Err = 1; // 0:成功;非0:错误号 32 | } 33 | 34 | 35 | /// PlayerBaseInfo 36 | 37 | message EnumPlayerBaseInfo 38 | { 39 | enum Error { 40 | NoErr = 0; 41 | ErrDB = 1; // 数据库错误 42 | ErrNoExist = 2; // 角色不存在 43 | } 44 | } 45 | 46 | message MsgPlayerBaseInfo 47 | { 48 | } 49 | 50 | message MsgPlayerBaseInfoResult 51 | { 52 | EnumPlayerBaseInfo.Error Err = 1; // 0:成功;非0:错误号 53 | string Name = 2; // 角色名字 54 | int32 Sex = 3; // 角色性别 55 | } 56 | -------------------------------------------------------------------------------- /example1_iogame/room/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | "github.com/fananchong/go-x/example1_iogame" 6 | ) 7 | 8 | var ( 9 | xargs *Args = &Args{} 10 | xlog common.ILogger = common.NewGLogger() 11 | ) 12 | 13 | type App struct { 14 | common.App 15 | } 16 | 17 | func NewApp() *App { 18 | this := &App{} 19 | this.Type = int(iogame.Room) 20 | this.Args = xargs 21 | this.Logger = xlog 22 | this.Derived = this 23 | return this 24 | } 25 | 26 | func (this *App) OnAppReady() { 27 | } 28 | 29 | func (this *App) OnAppShutDown() { 30 | } 31 | -------------------------------------------------------------------------------- /example1_iogame/room/args.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | type Args struct { 8 | common.ArgsBase 9 | } 10 | 11 | func (this *Args) OnInit() { 12 | } 13 | -------------------------------------------------------------------------------- /example1_iogame/room/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | app := NewApp() 5 | app.Run() 6 | } 7 | -------------------------------------------------------------------------------- /example1_iogame/service_def.go: -------------------------------------------------------------------------------- 1 | package iogame 2 | 3 | // 公共服务类型,请参见:go-x/common/service_def.go 4 | 5 | type ServerType int 6 | 7 | const ( 8 | Client ServerType = iota // 0 9 | Lobby = 10 // 10 10 | Room = 11 // 11 11 | ) 12 | -------------------------------------------------------------------------------- /govet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | docker run --rm -v "$PWD":/go/src/github.com/fananchong/go-x -w /go/src/github.com/fananchong/go-x/common_services golang go vet ./... 6 | #docker run --rm -v "$PWD":/go/src/github.com/fananchong/go-x -w /go/src/github.com/fananchong/go-x/example1_iogame golang go vet ./... 7 | 8 | -------------------------------------------------------------------------------- /k8s/gateway.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: gateway 5 | namespace: go-x 6 | labels: 7 | app: gateway 8 | spec: 9 | ports: 10 | - port: 30200 11 | name: "" 12 | clusterIP: None 13 | selector: 14 | app: gateway 15 | 16 | --- 17 | apiVersion: apps/v1 18 | kind: StatefulSet 19 | metadata: 20 | name: gateway 21 | namespace: go-x 22 | labels: 23 | app: gateway 24 | spec: 25 | serviceName: gateway 26 | selector: 27 | matchLabels: 28 | app: gateway 29 | replicas: 2 30 | template: 31 | metadata: 32 | labels: 33 | app: gateway 34 | spec: 35 | serviceAccountName: sa-go-x 36 | hostNetwork: true 37 | dnsPolicy: ClusterFirstWithHostNet 38 | containers: 39 | - name: gateway 40 | image: 127.0.0.1:5000/fananchong/go-x 41 | imagePullPolicy: Always 42 | command: [ "./gateway", "--common-loglevel=0" ] 43 | env: 44 | - name: POD_NAME 45 | valueFrom: 46 | fieldRef: 47 | fieldPath: metadata.name 48 | - name: POD_NAMESPACE 49 | valueFrom: 50 | fieldRef: 51 | fieldPath: metadata.namespace 52 | 53 | 54 | -------------------------------------------------------------------------------- /k8s/hub.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: hub 5 | namespace: go-x 6 | labels: 7 | app: hub 8 | spec: 9 | ports: 10 | - port: 30300 11 | name: "" 12 | clusterIP: None 13 | selector: 14 | app: hub 15 | 16 | --- 17 | apiVersion: apps/v1 18 | kind: StatefulSet 19 | metadata: 20 | name: hub 21 | namespace: go-x 22 | labels: 23 | app: hub 24 | spec: 25 | serviceName: hub 26 | selector: 27 | matchLabels: 28 | app: hub 29 | replicas: 2 30 | template: 31 | metadata: 32 | labels: 33 | app: hub 34 | spec: 35 | serviceAccountName: sa-go-x 36 | hostNetwork: true 37 | dnsPolicy: ClusterFirstWithHostNet 38 | containers: 39 | - name: hub 40 | image: 127.0.0.1:5000/fananchong/go-x 41 | imagePullPolicy: Always 42 | command: [ "./hub", "--common-loglevel=0" ] 43 | env: 44 | - name: POD_NAME 45 | valueFrom: 46 | fieldRef: 47 | fieldPath: metadata.name 48 | - name: POD_NAMESPACE 49 | valueFrom: 50 | fieldRef: 51 | fieldPath: metadata.namespace 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /k8s/lobby.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: lobby 5 | namespace: go-x 6 | labels: 7 | app: lobby 8 | spec: 9 | ports: 10 | - port: 31000 11 | name: "" 12 | clusterIP: None 13 | selector: 14 | app: lobby 15 | 16 | --- 17 | apiVersion: apps/v1 18 | kind: StatefulSet 19 | metadata: 20 | name: lobby 21 | namespace: go-x 22 | labels: 23 | app: lobby 24 | spec: 25 | serviceName: lobby 26 | selector: 27 | matchLabels: 28 | app: lobby 29 | replicas: 2 30 | template: 31 | metadata: 32 | labels: 33 | app: lobby 34 | spec: 35 | serviceAccountName: sa-go-x 36 | hostNetwork: true 37 | dnsPolicy: ClusterFirstWithHostNet 38 | containers: 39 | - name: lobby 40 | image: 127.0.0.1:5000/fananchong/go-x 41 | imagePullPolicy: Always 42 | command: [ "./lobby", "--common-loglevel=0" ] 43 | env: 44 | - name: POD_NAME 45 | valueFrom: 46 | fieldRef: 47 | fieldPath: metadata.name 48 | - name: POD_NAMESPACE 49 | valueFrom: 50 | fieldRef: 51 | fieldPath: metadata.namespace 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /k8s/login.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: login 5 | namespace: go-x 6 | labels: 7 | app: login 8 | spec: 9 | type: NodePort 10 | ports: 11 | - port: 8080 12 | nodePort: 30100 13 | selector: 14 | app: login 15 | 16 | --- 17 | apiVersion: apps/v1 18 | kind: Deployment 19 | metadata: 20 | name: login 21 | namespace: go-x 22 | labels: 23 | app: login 24 | spec: 25 | selector: 26 | matchLabels: 27 | app: login 28 | replicas: 1 29 | template: 30 | metadata: 31 | labels: 32 | app: login 33 | spec: 34 | serviceAccountName: sa-go-x 35 | containers: 36 | - name: login 37 | image: 127.0.0.1:5000/fananchong/go-x 38 | imagePullPolicy: Always 39 | command: [ "./login", "--common-loglevel=0" ] 40 | ports: 41 | - containerPort: 8080 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /k8s/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: go-x 5 | -------------------------------------------------------------------------------- /k8s/redis.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: redis 5 | namespace: go-x 6 | labels: 7 | app: redis 8 | spec: 9 | type: NodePort 10 | ports: 11 | - port: 32000 12 | targetPort: 6379 13 | nodePort: 32000 14 | selector: 15 | app: redis 16 | 17 | --- 18 | apiVersion: apps/v1 19 | kind: Deployment 20 | metadata: 21 | name: redis 22 | namespace: go-x 23 | labels: 24 | app: redis 25 | spec: 26 | selector: 27 | matchLabels: 28 | app: redis 29 | replicas: 1 30 | template: 31 | metadata: 32 | labels: 33 | app: redis 34 | spec: 35 | containers: 36 | - name: redis 37 | image: redis 38 | imagePullPolicy: IfNotPresent 39 | ports: 40 | - containerPort: 6379 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /k8s/room.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: room 5 | namespace: go-x 6 | labels: 7 | app: room 8 | spec: 9 | ports: 10 | - port: 31100 11 | name: "" 12 | clusterIP: None 13 | selector: 14 | app: room 15 | 16 | --- 17 | apiVersion: apps/v1 18 | kind: StatefulSet 19 | metadata: 20 | name: room 21 | namespace: go-x 22 | labels: 23 | app: room 24 | spec: 25 | serviceName: room 26 | selector: 27 | matchLabels: 28 | app: room 29 | replicas: 2 30 | template: 31 | metadata: 32 | labels: 33 | app: room 34 | spec: 35 | serviceAccountName: sa-go-x 36 | hostNetwork: true 37 | dnsPolicy: ClusterFirstWithHostNet 38 | containers: 39 | - name: room 40 | image: 127.0.0.1:5000/fananchong/go-x 41 | imagePullPolicy: Always 42 | command: [ "./room", "--common-loglevel=0" ] 43 | env: 44 | - name: POD_NAME 45 | valueFrom: 46 | fieldRef: 47 | fieldPath: metadata.name 48 | - name: POD_NAMESPACE 49 | valueFrom: 50 | fieldRef: 51 | fieldPath: metadata.namespace 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /k8s/service_account.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | labels: 5 | app: sa-go-x 6 | name: sa-go-x 7 | namespace: go-x 8 | 9 | --- 10 | apiVersion: rbac.authorization.k8s.io/v1beta1 11 | kind: ClusterRoleBinding 12 | metadata: 13 | name: sa-go-x 14 | labels: 15 | app: sa-go-x 16 | roleRef: 17 | apiGroup: rbac.authorization.k8s.io 18 | kind: ClusterRole 19 | name: cluster-admin 20 | subjects: 21 | - kind: ServiceAccount 22 | name: sa-go-x 23 | namespace: go-x 24 | 25 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | docker run --rm -e GOBIN=/go/bin/ -v "$PWD"/bin:/go/bin/ -v "$PWD":/go/src/github.com/fananchong/go-x -w /go/src/github.com/fananchong/go-x/common_services golang go test -v ip.go ip_test.go 6 | 7 | -------------------------------------------------------------------------------- /test/test_packet_loss/README.md: -------------------------------------------------------------------------------- 1 | 这里只演示下window下操作 2 | 3 | ### 编译 4 | 5 | 当前目录下执行: 6 | 7 | ```dos 8 | build.bat 9 | ``` 10 | 11 | ### 执行 12 | 13 | 当前目录下执行: 14 | 15 | ```dos 16 | cd bin 17 | server.exe 18 | client.exe 19 | ``` 20 | 21 | 在IE中, 键入 `127.0.0.1:8000?query=chart`,回车。 22 | 23 | ### 更多信息 24 | 25 | 请参考: http://blog.csdn.net/u013272009/article/details/78240679 26 | -------------------------------------------------------------------------------- /test/test_packet_loss/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR:\src\github.com\fananchong\go-x\test\test_packet_loss=\% 3 | set GOPATH=%BASEDIR% 4 | set GOBIN=%CURDIR%\bin 5 | go install ./... -------------------------------------------------------------------------------- /test/test_packet_loss/client/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | "github.com/fananchong/gochart" 6 | ) 7 | 8 | var ( 9 | xlog common.ILogger = common.NewDefaultLogger() 10 | ) 11 | 12 | type App struct { 13 | common.App 14 | } 15 | 16 | func NewApp() *App { 17 | this := &App{} 18 | this.Derived = this 19 | return this 20 | } 21 | 22 | var ( 23 | g_chart *Chart = nil 24 | ) 25 | 26 | func (this *App) OnAppReady() { 27 | g_chart = NewChart() 28 | s := &gochart.ChartServer{} 29 | s.AddChart("chart", g_chart, false) 30 | go func() { println(s.ListenAndServe(":8000").Error()) }() 31 | 32 | TcpClient() 33 | UdpClient() 34 | } 35 | 36 | func (this *App) OnAppShutDown() { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /test/test_packet_loss/client/chart.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/gochart" 5 | "sync" 6 | ) 7 | 8 | type Chart struct { 9 | gochart.ChartTime 10 | tcp []int64 11 | udp []int64 12 | m sync.Mutex 13 | } 14 | 15 | func NewChart() *Chart { 16 | this := &Chart{tcp: make([]int64, 0), udp: make([]int64, 0)} 17 | this.TickUnit = 100 18 | this.RefreshTime = DEFAULT_REFRESH_TIME 19 | this.SampleNum = DEFAULT_SAMPLE_NUM 20 | this.ChartType = "line" 21 | this.Title = "网络丢包测试" 22 | this.SubTitle = "服务器每100ms发送hello消息给客户端" 23 | this.YAxisText = "delay" 24 | this.YMax = "2000" 25 | this.ValueSuffix = "ms" 26 | this.TickLabelStep = "100" 27 | this.PlotLinesY = "{ color:'red', dashStyle:'longdashdot', value:100, width:1, label:{ text:'100ms', align:'left' } }" 28 | this.PlotLinesY += ",{ color:'red', dashStyle:'longdashdot', value:200, width:1, label:{ text:'200ms', align:'left' } }" 29 | return this 30 | } 31 | 32 | func (this *Chart) Update(now int64) map[string][]interface{} { 33 | datas := make(map[string][]interface{}) 34 | this.m.Lock() 35 | datas["tcp"] = make([]interface{}, 0) 36 | for _, v := range this.tcp { 37 | datas["tcp"] = append(datas["tcp"], v) 38 | } 39 | datas["udp"] = make([]interface{}, 0) 40 | for _, v := range this.udp { 41 | datas["udp"] = append(datas["udp"], v) 42 | } 43 | this.tcp = this.tcp[:0] 44 | this.udp = this.udp[:0] 45 | this.m.Unlock() 46 | return datas 47 | } 48 | 49 | func (this *Chart) AddTcpData(v int64) { 50 | this.m.Lock() 51 | this.tcp = append(this.tcp, v) 52 | this.m.Unlock() 53 | } 54 | 55 | func (this *Chart) AddUdpData(v int64) { 56 | this.m.Lock() 57 | this.udp = append(this.udp, v) 58 | this.m.Unlock() 59 | } 60 | -------------------------------------------------------------------------------- /test/test_packet_loss/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // usage: client --tcpaddr=192.168.1.3:3000 --udpaddr=192.168.1.3:3001 --log_dir=./log -stderrthreshold 0 4 | 5 | import ( 6 | "flag" 7 | ) 8 | 9 | var ( 10 | MSG = []byte("hello") 11 | DEFAULT_REFRESH_TIME = 1 12 | DEFAULT_SAMPLE_NUM = 2 * 60 / DEFAULT_REFRESH_TIME * 10 13 | ) 14 | 15 | func main() { 16 | tcpaddr := "" 17 | flag.StringVar(&tcpaddr, "tcpaddr", "localhost:3000", "tcp server address") 18 | udpaddr := "" 19 | flag.StringVar(&udpaddr, "udpaddr", "localhost:3001", "udp server address") 20 | 21 | app := NewApp() 22 | app.Run() 23 | } 24 | -------------------------------------------------------------------------------- /test/test_packet_loss/client/tcpclient.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "io" 6 | "net" 7 | "time" 8 | 9 | "github.com/fananchong/gotcp" 10 | ) 11 | 12 | func TcpClient() { 13 | faddr := flag.Lookup("tcpaddr") 14 | addr, _ := net.ResolveTCPAddr("tcp4", faddr.Value.String()) 15 | conn, err := net.DialTCP("tcp4", nil, addr) 16 | if err != nil { 17 | panic(err) 18 | } 19 | 20 | xlog.Infoln("connect to ", conn.RemoteAddr().String()) 21 | 22 | go func() { 23 | 24 | conn.SetNoDelay(true) 25 | conn.SetWriteBuffer(128 * 1024) 26 | conn.SetReadBuffer(128 * 1024) 27 | 28 | buf := gotcp.NewByteBuffer() 29 | msglen := len(MSG) 30 | var tempbuf [1024]byte 31 | for { 32 | leastlen := msglen - buf.RdSize() 33 | readnum, err := io.ReadAtLeast(conn, tempbuf[0:], leastlen) 34 | if err != nil { 35 | xlog.Infoln(err) 36 | return 37 | } 38 | buf.Append(tempbuf[:readnum]) 39 | now := time.Now().UnixNano() 40 | for buf.RdSize() >= msglen { 41 | msgbuff := buf.RdBuf() 42 | onTcpRecv(msgbuff[:msglen], now) 43 | buf.RdFlip(msglen) 44 | } 45 | } 46 | }() 47 | } 48 | 49 | var ( 50 | preTCPRecvTime int64 = 0 51 | ) 52 | 53 | func onTcpRecv(data []byte, now int64) { 54 | if len(data) != len(MSG) { 55 | panic("data len error!") 56 | } 57 | for i := 0; i < len(data); i++ { 58 | if data[i] != MSG[i] { 59 | panic("data error!") 60 | } 61 | } 62 | 63 | if preTCPRecvTime == 0 { 64 | preTCPRecvTime = now 65 | } 66 | 67 | detal := (now - preTCPRecvTime) / int64(time.Millisecond) 68 | preTCPRecvTime = now 69 | 70 | g_chart.AddTcpData(detal) 71 | } 72 | -------------------------------------------------------------------------------- /test/test_packet_loss/client/udpclient.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "net" 6 | "time" 7 | ) 8 | 9 | func UdpClient() { 10 | faddr := flag.Lookup("udpaddr") 11 | addr, _ := net.ResolveUDPAddr("udp", faddr.Value.String()) 12 | conn, err := net.DialUDP("udp", nil, addr) 13 | if err != nil { 14 | panic(err) 15 | } 16 | 17 | xlog.Infoln("connect to ", conn.RemoteAddr().String()) 18 | 19 | go func() { 20 | 21 | conn.SetWriteBuffer(128 * 1024) 22 | conn.SetReadBuffer(128 * 1024) 23 | conn.Write(MSG) 24 | 25 | for { 26 | var tempbuf [1024]byte 27 | readnum, err := conn.Read(tempbuf[0:]) 28 | if err != nil { 29 | xlog.Infoln(err) 30 | return 31 | } 32 | now := time.Now().UnixNano() 33 | onUdpRecv(tempbuf[:readnum], now) 34 | } 35 | }() 36 | } 37 | 38 | var ( 39 | preUDPRecvTime int64 = 0 40 | ) 41 | 42 | func onUdpRecv(data []byte, now int64) { 43 | if len(data) != len(MSG) { 44 | panic("data len error!") 45 | } 46 | for i := 0; i < len(data); i++ { 47 | if data[i] != MSG[i] { 48 | panic("data error!") 49 | } 50 | } 51 | 52 | if preUDPRecvTime == 0 { 53 | preUDPRecvTime = now 54 | } 55 | 56 | detal := (now - preUDPRecvTime) / int64(time.Millisecond) 57 | preUDPRecvTime = now 58 | 59 | g_chart.AddUdpData(detal) 60 | } 61 | -------------------------------------------------------------------------------- /test/test_packet_loss/server/app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/fananchong/go-x/common" 5 | ) 6 | 7 | var ( 8 | xlog common.ILogger = common.NewDefaultLogger() 9 | ) 10 | 11 | type App struct { 12 | common.App 13 | } 14 | 15 | func NewApp() *App { 16 | this := &App{} 17 | this.Derived = this 18 | return this 19 | } 20 | 21 | func (this *App) OnAppReady() { 22 | go TcpServer() 23 | go UdpServer() 24 | } 25 | 26 | func (this *App) OnAppShutDown() { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/test_packet_loss/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // usage: server --log_dir=./log -stderrthreshold 0 4 | 5 | var ( 6 | MSG = []byte("hello") 7 | ) 8 | 9 | func main() { 10 | app := NewApp() 11 | app.Run() 12 | } 13 | -------------------------------------------------------------------------------- /test/test_packet_loss/server/tcpserver.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | func TcpServer() { 9 | addr, _ := net.ResolveTCPAddr("tcp", ":3000") 10 | lis, err := net.ListenTCP("tcp", addr) 11 | if err != nil { 12 | panic(err) 13 | } 14 | 15 | for { 16 | conn, err := lis.AcceptTCP() 17 | if err != nil { 18 | xlog.Infoln(err) 19 | continue 20 | } 21 | 22 | xlog.Infoln("on connect. addr =", conn.RemoteAddr()) 23 | 24 | go func() { 25 | conn.SetNoDelay(true) 26 | conn.SetWriteBuffer(128 * 1024) 27 | conn.SetReadBuffer(128 * 1024) 28 | 29 | // 每100ms发送一次 hello消息 30 | t := time.NewTicker(100 * time.Millisecond) 31 | for { 32 | select { 33 | case <-t.C: 34 | conn.Write(MSG) 35 | } 36 | } 37 | }() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/test_packet_loss/server/udpserver.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | func UdpServer() { 9 | addr, err := net.ResolveUDPAddr("udp", ":3001") 10 | if err != nil { 11 | panic(err) 12 | } 13 | 14 | conn, err := net.ListenUDP("udp", addr) 15 | if err != nil { 16 | panic(err) 17 | } 18 | 19 | conn.SetWriteBuffer(128 * 1024) 20 | conn.SetReadBuffer(128 * 1024) 21 | 22 | var buf [20]byte 23 | _, raddr, err := conn.ReadFromUDP(buf[0:]) 24 | if err != nil { 25 | xlog.Infoln(err) 26 | return 27 | } 28 | 29 | // 每100ms发送一次 hello消息 30 | t := time.NewTicker(100 * time.Millisecond) 31 | for { 32 | select { 33 | case <-t.C: 34 | conn.WriteToUDP(MSG, raddr) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tools/redis/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### 知识细节 3 | 4 | http://blog.csdn.net/u013272009/article/details/78513251 5 | 6 | 7 | ### redis主从 8 | 9 | - install-redis.sh 10 | 11 | 12 | ### redis哨兵 13 | 14 | - install-redis-sentinel.sh 15 | 16 | 17 | ### redis集群 18 | 19 | - install-reids-cluster.sh 20 | 21 | 22 | ### Redis配置说明 23 | 24 | - timeout 0 25 | 26 | 指定在一个 client 空闲多少秒之后关闭连接(0 就是不管它) 27 | 28 | 29 | - tcp-keepalive 60 30 | 31 | 如果设置为非零,则在与客户端缺乏通讯的时候使用 SO_KEEPALIVE 发送 tcp acks 给客户端。 32 | 33 | 34 | - save "" 35 | 36 | 存 DB 到磁盘。格式:save <间隔时间(秒)> <写入次数> 37 | 38 | 39 | - maxmemory 5gb 40 | 41 | 最大使用内存 42 | -------------------------------------------------------------------------------- /tools/redis/docker-stack-redis-sentinel.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | 4 | sentinel1: 5 | image: redis 6 | deploy: 7 | placement: 8 | constraints: [node.labels.host_ip==IP1] 9 | replicas: 1 10 | restart_policy: 11 | delay: 60s 12 | ports: 13 | - "46379:26379" 14 | volumes: 15 | - data1:/data 16 | networks: 17 | - net 18 | command: /bin/bash -c "rm -f /data/redis_sentinel.conf && touch /data/redis_sentinel.conf && redis-server /data/redis_sentinel.conf --sentinel monitor NAME IP PORT NUM --sentinel down-after-milliseconds NAME 5000 --sentinel parallel-syncs NAME 1 --sentinel failover-timeout NAME 180000 --sentinel announce-ip IP1 --sentinel announce-port 46379" 19 | 20 | sentinel2: 21 | image: redis 22 | deploy: 23 | placement: 24 | constraints: [node.labels.host_ip==IP2] 25 | replicas: 1 26 | restart_policy: 27 | delay: 60s 28 | ports: 29 | - "46380:26379" 30 | volumes: 31 | - data2:/data 32 | networks: 33 | - net 34 | command: /bin/bash -c "rm -f /data/redis_sentinel.conf && touch /data/redis_sentinel.conf && redis-server /data/redis_sentinel.conf --sentinel monitor NAME IP PORT NUM --sentinel down-after-milliseconds NAME 5000 --sentinel parallel-syncs NAME 1 --sentinel failover-timeout NAME 180000 --sentinel announce-ip IP2 --sentinel announce-port 46380" 35 | 36 | sentinel3: 37 | image: redis 38 | deploy: 39 | placement: 40 | constraints: [node.labels.host_ip==IP3] 41 | replicas: 1 42 | restart_policy: 43 | delay: 60s 44 | ports: 45 | - "46381:26379" 46 | volumes: 47 | - data3:/data 48 | networks: 49 | - net 50 | command: /bin/bash -c "rm -f /data/redis_sentinel.conf && touch /data/redis_sentinel.conf && redis-server /data/redis_sentinel.conf --sentinel monitor NAME IP PORT NUM --sentinel down-after-milliseconds NAME 5000 --sentinel parallel-syncs NAME 1 --sentinel failover-timeout NAME 180000 --sentinel announce-ip IP3 --sentinel announce-port 46381" 51 | 52 | networks: 53 | net: 54 | volumes: 55 | data1: 56 | data2: 57 | data3: 58 | -------------------------------------------------------------------------------- /tools/redis/docker-stack-redis.yml: -------------------------------------------------------------------------------- 1 | version: "3.3" 2 | services: 3 | 4 | redis1: 5 | image: redis 6 | deploy: 7 | placement: 8 | constraints: [node.labels.host_ip==IP1] 9 | endpoint_mode: vip 10 | replicas: 1 11 | restart_policy: 12 | delay: 60s 13 | ports: 14 | - "16379:6379" 15 | networks: 16 | - net 17 | command: redis-server --save "" --maxmemory 5gb --timeout 0 --tcp-keepalive 60 --bind 0.0.0.0 --slave-announce-ip IP1 --slave-announce-port 16379 18 | 19 | redis2: 20 | image: redis 21 | deploy: 22 | placement: 23 | constraints: [node.labels.host_ip==IP2] 24 | endpoint_mode: vip 25 | replicas: 1 26 | restart_policy: 27 | delay: 60s 28 | ports: 29 | - "26379:6379" 30 | networks: 31 | - net 32 | command: redis-server --save "" --maxmemory 5gb --timeout 0 --tcp-keepalive 60 --bind 0.0.0.0 --slave-announce-ip IP2 --slave-announce-port 26379 --slaveof redis1 6379 33 | 34 | redis3: 35 | image: redis 36 | deploy: 37 | placement: 38 | constraints: [node.labels.host_ip==IP3] 39 | endpoint_mode: vip 40 | replicas: 1 41 | restart_policy: 42 | delay: 60s 43 | ports: 44 | - "36379:6379" 45 | networks: 46 | - net 47 | command: redis-server --save "" --maxmemory 5gb --timeout 0 --tcp-keepalive 60 --bind 0.0.0.0 --slave-announce-ip IP3 --slave-announce-port 36379 --slaveof redis1 6379 48 | 49 | 50 | networks: 51 | net: 52 | -------------------------------------------------------------------------------- /tools/redis/install-redis-cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker stack rm redis-cluster 4 | 5 | sleep 10s 6 | 7 | set -e 8 | 9 | [ "$HOST_IP1" ] || HOST_IP1="192.168.1.4" 10 | [ "$HOST_IP2" ] || HOST_IP2="192.168.1.4" 11 | [ "$HOST_IP3" ] || HOST_IP3="192.168.1.4" 12 | [ "$HOST_IP4" ] || HOST_IP4="192.168.1.4" 13 | [ "$HOST_IP5" ] || HOST_IP5="192.168.1.4" 14 | [ "$HOST_IP6" ] || HOST_IP6="192.168.1.4" 15 | 16 | cp -f docker-stack-redis-cluster.yml docker-stack-redis-cluster.yml.temp 17 | sed -i 's/IP1/'$HOST_IP1'/g' docker-stack-redis-cluster.yml.temp 18 | sed -i 's/IP2/'$HOST_IP2'/g' docker-stack-redis-cluster.yml.temp 19 | sed -i 's/IP3/'$HOST_IP3'/g' docker-stack-redis-cluster.yml.temp 20 | sed -i 's/IP4/'$HOST_IP4'/g' docker-stack-redis-cluster.yml.temp 21 | sed -i 's/IP5/'$HOST_IP5'/g' docker-stack-redis-cluster.yml.temp 22 | sed -i 's/IP6/'$HOST_IP6'/g' docker-stack-redis-cluster.yml.temp 23 | docker stack deploy -c ./docker-stack-redis-cluster.yml.temp redis-cluster 24 | rm -rf ./docker-stack-redis-cluster.yml.temp 25 | 26 | # temp 27 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39379 flushall 28 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39379 cluster reset 29 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39380 flushall 30 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39380 cluster reset 31 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39381 flushall 32 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39381 cluster reset 33 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39382 flushall 34 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39382 cluster reset 35 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39383 flushall 36 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39383 cluster reset 37 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39384 flushall 38 | docker run -it --rm redis redis-cli -h 192.168.1.4 -p 39384 cluster reset 39 | docker run -it --rm zvelo/redis-trib create --replicas 1 192.168.1.4:39379 192.168.1.4:39380 192.168.1.4:39381 192.168.1.4:39382 192.168.1.4:39383 192.168.1.4:39384 40 | 41 | -------------------------------------------------------------------------------- /tools/redis/install-redis-sentinel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | 6 | [ "$SENTINEL_NAME" ] || SENTINEL_NAME="mysentinel" 7 | [ "$MASTER_IP" ] || MASTER_IP="192.168.1.4" 8 | [ "$MASTER_PORT" ] || MASTER_PORT="16379" 9 | [ "$QUORUM" ] || QUORUM="2" 10 | [ "$HOST_IP1" ] || HOST_IP1="192.168.1.4" 11 | [ "$HOST_IP2" ] || HOST_IP2="192.168.1.4" 12 | [ "$HOST_IP3" ] || HOST_IP3="192.168.1.4" 13 | 14 | cp -f docker-stack-redis-sentinel.yml docker-stack-redis-sentinel.yml.temp 15 | sed -i 's/IP1/'$HOST_IP1'/g' docker-stack-redis-sentinel.yml.temp 16 | sed -i 's/IP2/'$HOST_IP2'/g' docker-stack-redis-sentinel.yml.temp 17 | sed -i 's/IP3/'$HOST_IP3'/g' docker-stack-redis-sentinel.yml.temp 18 | sed -i 's/NAME/'$SENTINEL_NAME'/g' docker-stack-redis-sentinel.yml.temp 19 | sed -i 's/IP/'$MASTER_IP'/g' docker-stack-redis-sentinel.yml.temp 20 | sed -i 's/PORT/'$MASTER_PORT'/g' docker-stack-redis-sentinel.yml.temp 21 | sed -i 's/NUM/'$QUORUM'/g' docker-stack-redis-sentinel.yml.temp 22 | docker stack deploy -c ./docker-stack-redis-sentinel.yml.temp redis-sentinel 23 | rm -rf ./docker-stack-redis-sentinel.yml.temp 24 | -------------------------------------------------------------------------------- /tools/redis/install-redis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | set -e 5 | 6 | [ "$HOST_IP1" ] || HOST_IP1="192.168.1.4" 7 | [ "$HOST_IP2" ] || HOST_IP2="192.168.1.4" 8 | [ "$HOST_IP3" ] || HOST_IP3="192.168.1.4" 9 | 10 | cp -f docker-stack-redis.yml docker-stack-redis.yml.temp 11 | sed -i 's/IP1/'$HOST_IP1'/g' docker-stack-redis.yml.temp 12 | sed -i 's/IP2/'$HOST_IP2'/g' docker-stack-redis.yml.temp 13 | sed -i 's/IP3/'$HOST_IP3'/g' docker-stack-redis.yml.temp 14 | docker stack deploy -c ./docker-stack-redis.yml.temp redis 15 | rm -rf ./docker-stack-redis.yml.temp 16 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.gitignore: -------------------------------------------------------------------------------- 1 | TAGS 2 | tags 3 | .*.swp 4 | tomlcheck/tomlcheck 5 | toml.test 6 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.1 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | - 1.6 9 | - tip 10 | install: 11 | - go install ./... 12 | - go get github.com/BurntSushi/toml-test 13 | script: 14 | - export PATH="$PATH:$HOME/gopath/bin" 15 | - make test 16 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COMPATIBLE: -------------------------------------------------------------------------------- 1 | Compatible with TOML version 2 | [v0.4.0](https://github.com/toml-lang/toml/blob/v0.4.0/versions/en/toml-v0.4.0.md) 3 | 4 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COPYING: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 TOML authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | go install ./... 3 | 4 | test: install 5 | go test -v 6 | toml-test toml-test-decoder 7 | toml-test -encoder toml-test-encoder 8 | 9 | fmt: 10 | gofmt -w *.go */*.go 11 | colcheck *.go */*.go 12 | 13 | tags: 14 | find ./ -name '*.go' -print0 | xargs -0 gotags > TAGS 15 | 16 | push: 17 | git push origin master 18 | git push github master 19 | 20 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package toml provides facilities for decoding and encoding TOML configuration 3 | files via reflection. There is also support for delaying decoding with 4 | the Primitive type, and querying the set of keys in a TOML document with the 5 | MetaData type. 6 | 7 | The specification implemented: https://github.com/toml-lang/toml 8 | 9 | The sub-command github.com/BurntSushi/toml/cmd/tomlv can be used to verify 10 | whether a file is a valid TOML document. It can also be used to print the 11 | type of each key in a TOML document. 12 | 13 | Testing 14 | 15 | There are two important types of tests used for this package. The first is 16 | contained inside '*_test.go' files and uses the standard Go unit testing 17 | framework. These tests are primarily devoted to holistically testing the 18 | decoder and encoder. 19 | 20 | The second type of testing is used to verify the implementation's adherence 21 | to the TOML specification. These tests have been factored into their own 22 | project: https://github.com/BurntSushi/toml-test 23 | 24 | The reason the tests are in a separate project is so that they can be used by 25 | any implementation of TOML. Namely, it is language agnostic. 26 | */ 27 | package toml 28 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/encoding_types.go: -------------------------------------------------------------------------------- 1 | // +build go1.2 2 | 3 | package toml 4 | 5 | // In order to support Go 1.1, we define our own TextMarshaler and 6 | // TextUnmarshaler types. For Go 1.2+, we just alias them with the 7 | // standard library interfaces. 8 | 9 | import ( 10 | "encoding" 11 | ) 12 | 13 | // TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here 14 | // so that Go 1.1 can be supported. 15 | type TextMarshaler encoding.TextMarshaler 16 | 17 | // TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined 18 | // here so that Go 1.1 can be supported. 19 | type TextUnmarshaler encoding.TextUnmarshaler 20 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/encoding_types_1.1.go: -------------------------------------------------------------------------------- 1 | // +build !go1.2 2 | 3 | package toml 4 | 5 | // These interfaces were introduced in Go 1.2, so we add them manually when 6 | // compiling for Go 1.1. 7 | 8 | // TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here 9 | // so that Go 1.1 can be supported. 10 | type TextMarshaler interface { 11 | MarshalText() (text []byte, err error) 12 | } 13 | 14 | // TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined 15 | // here so that Go 1.1 can be supported. 16 | type TextUnmarshaler interface { 17 | UnmarshalText(text []byte) error 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/session.vim: -------------------------------------------------------------------------------- 1 | au BufWritePost *.go silent!make tags > /dev/null 2>&1 2 | -------------------------------------------------------------------------------- /vendor/github.com/FZambia/sentinel/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/FZambia/sentinel/README.md: -------------------------------------------------------------------------------- 1 | go-sentinel 2 | =========== 3 | 4 | Redis Sentinel support for [redigo](https://github.com/gomodule/redigo) library. 5 | 6 | Documentation 7 | ------------- 8 | 9 | - [API Reference](http://godoc.org/github.com/FZambia/sentinel) 10 | 11 | Alternative solution 12 | -------------------- 13 | 14 | You can alternatively configure Haproxy between your application and Redis to proxy requests to Redis master instance if you only need HA: 15 | 16 | ``` 17 | listen redis 18 | server redis-01 127.0.0.1:6380 check port 6380 check inter 2s weight 1 inter 2s downinter 5s rise 10 fall 2 19 | server redis-02 127.0.0.1:6381 check port 6381 check inter 2s weight 1 inter 2s downinter 5s rise 10 fall 2 backup 20 | bind *:6379 21 | mode tcp 22 | option tcpka 23 | option tcplog 24 | option tcp-check 25 | tcp-check send PING\r\n 26 | tcp-check expect string +PONG 27 | tcp-check send info\ replication\r\n 28 | tcp-check expect string role:master 29 | tcp-check send QUIT\r\n 30 | tcp-check expect string +OK 31 | balance roundrobin 32 | ``` 33 | 34 | This way you don't need to use this library. 35 | 36 | License 37 | ------- 38 | 39 | Library is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). 40 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.8.x 7 | - 1.9.x 8 | - tip 9 | 10 | os: 11 | - linux 12 | 13 | matrix: 14 | fast_finish: true 15 | allow_failures: 16 | - go: tip 17 | 18 | before_install: 19 | - go get -v github.com/stretchr/testify 20 | 21 | script: 22 | - go test -v ./... 23 | 24 | notifications: 25 | email: false 26 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/README.md: -------------------------------------------------------------------------------- 1 | ### go-simplejson 2 | 3 | a Go package to interact with arbitrary JSON 4 | 5 | [![Build Status](https://secure.travis-ci.org/bitly/go-simplejson.png)](http://travis-ci.org/bitly/go-simplejson) 6 | 7 | ### Importing 8 | 9 | import github.com/bitly/go-simplejson 10 | 11 | ### Documentation 12 | 13 | Visit the docs on [gopkgdoc](http://godoc.org/github.com/bitly/go-simplejson) 14 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/simplejson_go10.go: -------------------------------------------------------------------------------- 1 | // +build !go1.1 2 | 3 | package simplejson 4 | 5 | import ( 6 | "encoding/json" 7 | "errors" 8 | "io" 9 | "reflect" 10 | ) 11 | 12 | // NewFromReader returns a *Json by decoding from an io.Reader 13 | func NewFromReader(r io.Reader) (*Json, error) { 14 | j := new(Json) 15 | dec := json.NewDecoder(r) 16 | err := dec.Decode(&j.data) 17 | return j, err 18 | } 19 | 20 | // Implements the json.Unmarshaler interface. 21 | func (j *Json) UnmarshalJSON(p []byte) error { 22 | return json.Unmarshal(p, &j.data) 23 | } 24 | 25 | // Float64 coerces into a float64 26 | func (j *Json) Float64() (float64, error) { 27 | switch j.data.(type) { 28 | case float32, float64: 29 | return reflect.ValueOf(j.data).Float(), nil 30 | case int, int8, int16, int32, int64: 31 | return float64(reflect.ValueOf(j.data).Int()), nil 32 | case uint, uint8, uint16, uint32, uint64: 33 | return float64(reflect.ValueOf(j.data).Uint()), nil 34 | } 35 | return 0, errors.New("invalid value type") 36 | } 37 | 38 | // Int coerces into an int 39 | func (j *Json) Int() (int, error) { 40 | switch j.data.(type) { 41 | case float32, float64: 42 | return int(reflect.ValueOf(j.data).Float()), nil 43 | case int, int8, int16, int32, int64: 44 | return int(reflect.ValueOf(j.data).Int()), nil 45 | case uint, uint8, uint16, uint32, uint64: 46 | return int(reflect.ValueOf(j.data).Uint()), nil 47 | } 48 | return 0, errors.New("invalid value type") 49 | } 50 | 51 | // Int64 coerces into an int64 52 | func (j *Json) Int64() (int64, error) { 53 | switch j.data.(type) { 54 | case float32, float64: 55 | return int64(reflect.ValueOf(j.data).Float()), nil 56 | case int, int8, int16, int32, int64: 57 | return reflect.ValueOf(j.data).Int(), nil 58 | case uint, uint8, uint16, uint32, uint64: 59 | return int64(reflect.ValueOf(j.data).Uint()), nil 60 | } 61 | return 0, errors.New("invalid value type") 62 | } 63 | 64 | // Uint64 coerces into an uint64 65 | func (j *Json) Uint64() (uint64, error) { 66 | switch j.data.(type) { 67 | case float32, float64: 68 | return uint64(reflect.ValueOf(j.data).Float()), nil 69 | case int, int8, int16, int32, int64: 70 | return uint64(reflect.ValueOf(j.data).Int()), nil 71 | case uint, uint8, uint16, uint32, uint64: 72 | return reflect.ValueOf(j.data).Uint(), nil 73 | } 74 | return 0, errors.New("invalid value type") 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/.gitignore: -------------------------------------------------------------------------------- 1 | assets 2 | _output/ 3 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | sudo: required 4 | 5 | go: 6 | - 1.8 7 | - 1.9 8 | 9 | services: 10 | - docker 11 | 12 | env: 13 | - K8S_CLIENT_TEST=1 KUBECONFIG=scripts/kubeconfig 14 | 15 | install: 16 | - go get -v ./... 17 | - go get -v github.com/ghodss/yaml # Required for examples. 18 | - ./scripts/run-kube.sh 19 | - curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.1/bin/linux/amd64/kubectl 20 | - chmod +x kubectl 21 | - mv kubectl $GOPATH/bin 22 | 23 | script: 24 | - make 25 | - make test 26 | - make test-examples 27 | - make verify-generate 28 | 29 | 30 | notifications: 31 | email: false 32 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/Makefile: -------------------------------------------------------------------------------- 1 | KUBE_VERSION=1.10.1 2 | 3 | build: 4 | go build -v ./... 5 | 6 | test: 7 | go test -v ./... 8 | 9 | test-examples: 10 | @for example in $(shell find examples/ -name '*.go'); do \ 11 | go build -v $$example || exit 1; \ 12 | done 13 | 14 | .PHONY: generate 15 | generate: _output/kubernetes _output/bin/protoc _output/bin/gomvpkg _output/bin/protoc-gen-gofast _output/src/github.com/golang/protobuf 16 | ./scripts/generate.sh 17 | go run scripts/register.go 18 | cp scripts/json.go.partial apis/meta/v1/json.go 19 | 20 | .PHONY: verify-generate 21 | verify-generate: generate 22 | ./scripts/git-diff.sh 23 | 24 | _output/bin/protoc-gen-gofast: 25 | ./scripts/go-install.sh \ 26 | https://github.com/gogo/protobuf \ 27 | github.com/gogo/protobuf \ 28 | github.com/gogo/protobuf/protoc-gen-gofast \ 29 | tags/v0.5 30 | 31 | _output/bin/gomvpkg: 32 | ./scripts/go-install.sh \ 33 | https://github.com/golang/tools \ 34 | golang.org/x/tools \ 35 | golang.org/x/tools/cmd/gomvpkg \ 36 | fbec762f837dc349b73d1eaa820552e2ad177942 37 | 38 | _output/src/github.com/golang/protobuf: 39 | git clone https://github.com/golang/protobuf _output/src/github.com/golang/protobuf 40 | 41 | _output/bin/protoc: 42 | ./scripts/get-protoc.sh 43 | 44 | _output/kubernetes: 45 | mkdir -p _output 46 | curl -o _output/kubernetes.zip -L https://github.com/kubernetes/kubernetes/archive/v$(KUBE_VERSION).zip 47 | unzip _output/kubernetes.zip -d _output > /dev/null 48 | mv _output/kubernetes-$(KUBE_VERSION) _output/kubernetes 49 | 50 | .PHONY: clean 51 | clean: 52 | rm -rf _output 53 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/apis/apiextensions/v1beta1/register.go: -------------------------------------------------------------------------------- 1 | package v1beta1 2 | 3 | import "github.com/ericchiang/k8s" 4 | 5 | func init() { 6 | k8s.Register("apiextensions.k8s.io", "v1beta1", "customresourcedefinitions", false, &CustomResourceDefinition{}) 7 | 8 | k8s.RegisterList("apiextensions.k8s.io", "v1beta1", "customresourcedefinitions", false, &CustomResourceDefinitionList{}) 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/apis/core/v1/register.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import "github.com/ericchiang/k8s" 4 | 5 | func init() { 6 | k8s.Register("", "v1", "componentstatuses", false, &ComponentStatus{}) 7 | k8s.Register("", "v1", "configmaps", true, &ConfigMap{}) 8 | k8s.Register("", "v1", "endpoints", true, &Endpoints{}) 9 | k8s.Register("", "v1", "limitranges", true, &LimitRange{}) 10 | k8s.Register("", "v1", "namespaces", false, &Namespace{}) 11 | k8s.Register("", "v1", "nodes", false, &Node{}) 12 | k8s.Register("", "v1", "persistentvolumeclaims", true, &PersistentVolumeClaim{}) 13 | k8s.Register("", "v1", "persistentvolumes", false, &PersistentVolume{}) 14 | k8s.Register("", "v1", "pods", true, &Pod{}) 15 | k8s.Register("", "v1", "replicationcontrollers", true, &ReplicationController{}) 16 | k8s.Register("", "v1", "resourcequotas", true, &ResourceQuota{}) 17 | k8s.Register("", "v1", "secrets", true, &Secret{}) 18 | k8s.Register("", "v1", "services", true, &Service{}) 19 | k8s.Register("", "v1", "serviceaccounts", true, &ServiceAccount{}) 20 | 21 | k8s.RegisterList("", "v1", "componentstatuses", false, &ComponentStatusList{}) 22 | k8s.RegisterList("", "v1", "configmaps", true, &ConfigMapList{}) 23 | k8s.RegisterList("", "v1", "endpoints", true, &EndpointsList{}) 24 | k8s.RegisterList("", "v1", "limitranges", true, &LimitRangeList{}) 25 | k8s.RegisterList("", "v1", "namespaces", false, &NamespaceList{}) 26 | k8s.RegisterList("", "v1", "nodes", false, &NodeList{}) 27 | k8s.RegisterList("", "v1", "persistentvolumeclaims", true, &PersistentVolumeClaimList{}) 28 | k8s.RegisterList("", "v1", "persistentvolumes", false, &PersistentVolumeList{}) 29 | k8s.RegisterList("", "v1", "pods", true, &PodList{}) 30 | k8s.RegisterList("", "v1", "replicationcontrollers", true, &ReplicationControllerList{}) 31 | k8s.RegisterList("", "v1", "resourcequotas", true, &ResourceQuotaList{}) 32 | k8s.RegisterList("", "v1", "secrets", true, &SecretList{}) 33 | k8s.RegisterList("", "v1", "services", true, &ServiceList{}) 34 | k8s.RegisterList("", "v1", "serviceaccounts", true, &ServiceAccountList{}) 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/apis/meta/v1/json.go: -------------------------------------------------------------------------------- 1 | package v1 2 | 3 | import ( 4 | "encoding/json" 5 | "time" 6 | ) 7 | 8 | // JSON marshaling logic for the Time type so it can be used for custom 9 | // resources, which serialize to JSON. 10 | 11 | func (t Time) MarshalJSON() ([]byte, error) { 12 | var seconds, nanos int64 13 | if t.Seconds != nil { 14 | seconds = *t.Seconds 15 | } 16 | if t.Nanos != nil { 17 | nanos = int64(*t.Nanos) 18 | } 19 | return json.Marshal(time.Unix(seconds, nanos)) 20 | } 21 | 22 | func (t *Time) UnmarshalJSON(p []byte) error { 23 | var t1 time.Time 24 | if err := json.Unmarshal(p, &t1); err != nil { 25 | return err 26 | } 27 | seconds := t1.Unix() 28 | nanos := int32(t1.UnixNano()) 29 | t.Seconds = &seconds 30 | t.Nanos = &nanos 31 | return nil 32 | } 33 | 34 | // Status must implement json.Unmarshaler for the codec to deserialize a JSON 35 | // payload into it. 36 | // 37 | // See https://github.com/ericchiang/k8s/issues/82 38 | 39 | type jsonStatus Status 40 | 41 | func (s *Status) UnmarshalJSON(data []byte) error { 42 | var j jsonStatus 43 | if err := json.Unmarshal(data, &j); err != nil { 44 | return err 45 | } 46 | *s = Status(j) 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/discovery.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | import ( 4 | "context" 5 | "path" 6 | 7 | metav1 "github.com/ericchiang/k8s/apis/meta/v1" 8 | ) 9 | 10 | type Version struct { 11 | Major string `json:"major"` 12 | Minor string `json:"minor"` 13 | GitVersion string `json:"gitVersion"` 14 | GitCommit string `json:"gitCommit"` 15 | GitTreeState string `json:"gitTreeState"` 16 | BuildDate string `json:"buildDate"` 17 | GoVersion string `json:"goVersion"` 18 | Compiler string `json:"compiler"` 19 | Platform string `json:"platform"` 20 | } 21 | 22 | // Discovery is a client used to determine the API version and supported 23 | // resources of the server. 24 | type Discovery struct { 25 | client *Client 26 | } 27 | 28 | func NewDiscoveryClient(c *Client) *Discovery { 29 | return &Discovery{c} 30 | } 31 | 32 | func (d *Discovery) get(ctx context.Context, path string, resp interface{}) error { 33 | return d.client.do(ctx, "GET", urlForPath(d.client.Endpoint, path), nil, resp) 34 | } 35 | 36 | func (d *Discovery) Version(ctx context.Context) (*Version, error) { 37 | var v Version 38 | if err := d.get(ctx, "version", &v); err != nil { 39 | return nil, err 40 | } 41 | return &v, nil 42 | } 43 | 44 | func (d *Discovery) APIGroups(ctx context.Context) (*metav1.APIGroupList, error) { 45 | var groups metav1.APIGroupList 46 | if err := d.get(ctx, "apis", &groups); err != nil { 47 | return nil, err 48 | } 49 | return &groups, nil 50 | } 51 | 52 | func (d *Discovery) APIGroup(ctx context.Context, name string) (*metav1.APIGroup, error) { 53 | var group metav1.APIGroup 54 | if err := d.get(ctx, path.Join("apis", name), &group); err != nil { 55 | return nil, err 56 | } 57 | return &group, nil 58 | } 59 | 60 | func (d *Discovery) APIResources(ctx context.Context, groupName, groupVersion string) (*metav1.APIResourceList, error) { 61 | var list metav1.APIResourceList 62 | if err := d.get(ctx, path.Join("apis", groupName, groupVersion), &list); err != nil { 63 | return nil, err 64 | } 65 | return &list, nil 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/ericchiang/k8s/runtime/schema/generated.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: k8s.io/apimachinery/pkg/runtime/schema/generated.proto 3 | 4 | /* 5 | Package schema is a generated protocol buffer package. 6 | 7 | It is generated from these files: 8 | k8s.io/apimachinery/pkg/runtime/schema/generated.proto 9 | 10 | It has these top-level messages: 11 | */ 12 | package schema 13 | 14 | import proto "github.com/golang/protobuf/proto" 15 | import fmt "fmt" 16 | import math "math" 17 | import _ "github.com/ericchiang/k8s/util/intstr" 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // This is a compile-time assertion to ensure that this generated file 25 | // is compatible with the proto package it is being compiled against. 26 | // A compilation error at this line likely means your copy of the 27 | // proto package needs to be updated. 28 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 29 | 30 | func init() { 31 | proto.RegisterFile("k8s.io/apimachinery/pkg/runtime/schema/generated.proto", fileDescriptorGenerated) 32 | } 33 | 34 | var fileDescriptorGenerated = []byte{ 35 | // 138 bytes of a gzipped FileDescriptorProto 36 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xcb, 0xb6, 0x28, 0xd6, 37 | 0xcb, 0xcc, 0xd7, 0x4f, 0x2c, 0xc8, 0xcc, 0x4d, 0x4c, 0xce, 0xc8, 0xcc, 0x4b, 0x2d, 0xaa, 0xd4, 38 | 0x2f, 0xc8, 0x4e, 0xd7, 0x2f, 0x2a, 0xcd, 0x2b, 0xc9, 0xcc, 0x4d, 0xd5, 0x2f, 0x4e, 0xce, 0x48, 39 | 0xcd, 0x4d, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0x4a, 0x2c, 0x49, 0x4d, 0xd1, 0x2b, 0x28, 0xca, 40 | 0x2f, 0xc9, 0x17, 0x52, 0x83, 0xe8, 0xd3, 0x43, 0xd6, 0xa7, 0x57, 0x90, 0x9d, 0xae, 0x07, 0xd5, 41 | 0xa7, 0x07, 0xd1, 0x27, 0x65, 0x8c, 0xcb, 0xfc, 0xd2, 0x92, 0xcc, 0x1c, 0xfd, 0xcc, 0xbc, 0x92, 42 | 0xe2, 0x92, 0x22, 0x74, 0xc3, 0x9d, 0x24, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 43 | 0xc1, 0x23, 0x39, 0xc6, 0x19, 0x8f, 0xe5, 0x18, 0xa2, 0xd8, 0x20, 0xc6, 0x01, 0x02, 0x00, 0x00, 44 | 0xff, 0xff, 0xf9, 0x8e, 0xdb, 0x42, 0xaf, 0x00, 0x00, 0x00, 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/glog/README: -------------------------------------------------------------------------------- 1 | glog 2 | ==== 3 | 4 | Leveled execution logs for Go. 5 | 6 | This is an efficient pure Go implementation of leveled logs in the 7 | manner of the open source C++ package 8 | https://github.com/google/glog 9 | 10 | By binding methods to booleans it is possible to use the log package 11 | without paying the expense of evaluating the arguments to the log. 12 | Through the -vmodule flag, the package also provides fine-grained 13 | control over logging at the file level. 14 | 15 | The comment from glog.go introduces the ideas: 16 | 17 | Package glog implements logging analogous to the Google-internal 18 | C++ INFO/ERROR/V setup. It provides functions Info, Warning, 19 | Error, Fatal, plus formatting variants such as Infof. It 20 | also provides V-style logging controlled by the -v and 21 | -vmodule=file=2 flags. 22 | 23 | Basic examples: 24 | 25 | glog.Info("Prepare to repel boarders") 26 | 27 | glog.Fatalf("Initialization failed: %s", err) 28 | 29 | See the documentation for the V function for an explanation 30 | of these examples: 31 | 32 | if glog.V(2) { 33 | glog.Info("Starting transaction...") 34 | } 35 | 36 | glog.V(2).Infoln("Processed", nItems, "elements") 37 | 38 | 39 | The repository contains an open source version of the log package 40 | used inside Google. The master copy of the source lives inside 41 | Google, not here. The code in this repo is for export only and is not itself 42 | under development. Feature requests will be ignored. 43 | 44 | Send bug reports to golang-nuts@googlegroups.com. 45 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/glog/glog_ext.go: -------------------------------------------------------------------------------- 1 | package glog 2 | 3 | import "fmt" 4 | 5 | func (l *loggingT) Init() bool { 6 | return true 7 | } 8 | 9 | func (l *loggingT) Flush() { 10 | l.lockAndFlushAll() 11 | } 12 | 13 | func (l *loggingT) Debug(args ...interface{}) { 14 | fmt.Print(args...) 15 | } 16 | 17 | func (l *loggingT) Debugln(args ...interface{}) { 18 | fmt.Println(args...) 19 | } 20 | 21 | func (l *loggingT) Debugf(format string, args ...interface{}) { 22 | fmt.Printf(format, args...) 23 | } 24 | 25 | func (l *loggingT) Print(args ...interface{}) { 26 | l.print(infoLog, args...) 27 | } 28 | 29 | func (l *loggingT) Println(args ...interface{}) { 30 | l.println(infoLog, args...) 31 | } 32 | 33 | func (l *loggingT) Printf(format string, args ...interface{}) { 34 | l.printf(infoLog, format, args...) 35 | } 36 | 37 | func (l *loggingT) Info(args ...interface{}) { 38 | l.print(infoLog, args...) 39 | } 40 | 41 | func (l *loggingT) Infoln(args ...interface{}) { 42 | l.println(infoLog, args...) 43 | } 44 | 45 | func (l *loggingT) Infof(format string, args ...interface{}) { 46 | l.printf(infoLog, format, args...) 47 | } 48 | 49 | func (l *loggingT) Warning(args ...interface{}) { 50 | l.print(warningLog, args...) 51 | } 52 | 53 | func (l *loggingT) Warningln(args ...interface{}) { 54 | l.println(warningLog, args...) 55 | } 56 | 57 | func (l *loggingT) Warningf(format string, args ...interface{}) { 58 | l.printf(warningLog, format, args...) 59 | } 60 | 61 | func (l *loggingT) Error(args ...interface{}) { 62 | l.print(errorLog, args...) 63 | } 64 | 65 | func (l *loggingT) Errorln(args ...interface{}) { 66 | l.println(errorLog, args...) 67 | } 68 | 69 | func (l *loggingT) Errorf(format string, args ...interface{}) { 70 | l.printf(errorLog, format, args...) 71 | } 72 | 73 | func (l *loggingT) Fatal(args ...interface{}) { 74 | l.print(fatalLog, args...) 75 | } 76 | 77 | func (l *loggingT) Fatalln(args ...interface{}) { 78 | l.println(fatalLog, args...) 79 | } 80 | 81 | func (l *loggingT) Fatalf(format string, args ...interface{}) { 82 | l.printf(fatalLog, format, args...) 83 | } 84 | 85 | func (l *loggingT) SetLogLevel(level int) { 86 | l.stderrThreshold = severity(level) 87 | } 88 | 89 | func (l *loggingT) SetLogDir(dir string) { 90 | logDir = dir 91 | } 92 | 93 | type LoggingT = loggingT 94 | 95 | func GetLogger() *LoggingT { 96 | return &logging 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang 2 | 3 | WORKDIR /app/bin 4 | 5 | COPY bin/redis2go /app/bin/ 6 | 7 | VOLUME /app/input 8 | VOLUME /app/output 9 | 10 | ENTRYPOINT ["./redis2go", "--input_dir=/app/input/", "--output_dir=/app/output/"] 11 | 12 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 范安崇 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | docker run --rm -e GOBIN=/go/bin/ -v "$PWD"/bin:/go/bin/ -v "$PWD":/go/src/github.com/fananchong/go-redis-orm.v2 -w /go/src/github.com/fananchong/go-redis-orm.v2 golang go install ./... 6 | 7 | #docker build -t redis2go . 8 | 9 | #docker tag redis2go:latest fananchong/redis2go:latest 10 | 11 | #docker push fananchong/redis2go:latest 12 | 13 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/common.go: -------------------------------------------------------------------------------- 1 | package go_redis_orm 2 | 3 | import "errors" 4 | 5 | type IClient interface { 6 | Do(commandName string, args ...interface{}) (reply interface{}, err error) 7 | } 8 | 9 | type NewRedisType func(dbName string, addrs []string, password string, dbindex int) (IClient, error) 10 | 11 | func SetNewRedisHandler(handler NewRedisType) { 12 | g_redismgr.SetNewRedisHandler(handler) 13 | } 14 | 15 | func CreateDB(dbName string, addrs []string, password string, dbindex int)error { 16 | return g_redismgr.Create(dbName, addrs, password, dbindex) 17 | } 18 | 19 | func GetDB(dbName string) IClient { 20 | return g_redismgr.Get(dbName) 21 | } 22 | 23 | var ERR_ISNOT_EXIST_KEY = errors.New("is not exist thi key") 24 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/default_redis_client.go: -------------------------------------------------------------------------------- 1 | package go_redis_orm 2 | 3 | import ( 4 | "github.com/fananchong/goredis" 5 | ) 6 | 7 | type DefaultRedisClient struct { 8 | *goredis.Client 9 | } 10 | 11 | func NewDefaultRedisClient(dbName string, addrs []string, password string, dbindex int) (IClient, error) { 12 | this := &DefaultRedisClient{} 13 | option := goredis.NewDefaultOption() 14 | option.Password = password 15 | option.DBIndex = dbindex 16 | client, err := goredis.NewClient(dbName, addrs, option) 17 | if err != nil { 18 | return nil, err 19 | } 20 | this.Client = client 21 | return this, nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/go-redis-orm.v2/redis_mgr.go: -------------------------------------------------------------------------------- 1 | package go_redis_orm 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | var g_redismgr *RedisMgr 8 | 9 | type RedisMgr struct { 10 | dbs map[string]IClient 11 | newRedis NewRedisType 12 | } 13 | 14 | func NewRedisMgr() *RedisMgr { 15 | return &RedisMgr{ 16 | dbs: make(map[string]IClient), 17 | } 18 | } 19 | 20 | func (this *RedisMgr) Create(dbName string, addrs []string, password string, dbindex int) error { 21 | if _, ok := this.dbs[dbName]; ok { 22 | return nil 23 | } 24 | if this.newRedis == nil { 25 | return errors.New("no set new handler!") 26 | } 27 | db, err := this.newRedis(dbName, addrs, password, dbindex) 28 | if err != nil { 29 | return err 30 | } 31 | this.dbs[dbName] = db 32 | return nil 33 | } 34 | 35 | func (this *RedisMgr) Get(dbName string) IClient { 36 | if db, ok := this.dbs[dbName]; ok { 37 | return db 38 | } 39 | return nil 40 | } 41 | 42 | func (this *RedisMgr) SetNewRedisHandler(handler NewRedisType) { 43 | this.newRedis = handler 44 | } 45 | 46 | func init() { 47 | g_redismgr = NewRedisMgr() 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gochart/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | download/win64/gochart/ 27 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gochart/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, zieckey 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gochart/README.md: -------------------------------------------------------------------------------- 1 | gochart 2 | ======= 3 | 4 | [中文说明](http://blog.codeg.cn/2014/12/27/gochart-info/) 5 | 6 | 7 | ### 改进点 8 | 9 | - 将gochart改成库形式提供 10 | 11 | - 不依赖外网 12 | 13 | - 定时刷新 14 | 15 | - 提供X轴为时间轴的图表类型 16 | 17 | - 保存图表数据 18 | 19 | - 回放图表数据 20 | 21 | 22 | ### 使用说明 23 | 24 | - 如何使用该库请参考:https://github.com/fananchong/gochart_example 25 | 26 | - 执行程序前,需要将js目录拷贝至可执行程序同级目录下 27 | 28 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gochart/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR:\src\github.com\fananchong\gochart\=\% 3 | set GOPATH=%BASEDIR%;%CURDIR%\Godeps 4 | set GOBIN=%CURDIR%\bin 5 | go install ./... 6 | pause -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gochart/log.go: -------------------------------------------------------------------------------- 1 | package gochart 2 | 3 | type ILogger interface { 4 | Error(args ...interface{}) 5 | Errorf(format string, args ...interface{}) 6 | Errorln(args ...interface{}) 7 | Info(args ...interface{}) 8 | Infof(format string, args ...interface{}) 9 | Infoln(args ...interface{}) 10 | } 11 | 12 | type DefaultLogger struct { 13 | } 14 | 15 | func NewDefaultLogger() *DefaultLogger { 16 | return &DefaultLogger{} 17 | } 18 | 19 | func (this *DefaultLogger) Error(args ...interface{}) { 20 | } 21 | 22 | func (this *DefaultLogger) Errorf(format string, args ...interface{}) { 23 | } 24 | 25 | func (this *DefaultLogger) Errorln(args ...interface{}) { 26 | } 27 | 28 | func (this *DefaultLogger) Info(args ...interface{}) { 29 | } 30 | 31 | func (this *DefaultLogger) Infof(format string, args ...interface{}) { 32 | } 33 | 34 | func (this *DefaultLogger) Infoln(args ...interface{}) { 35 | } 36 | 37 | var ( 38 | xlog ILogger = NewDefaultLogger() 39 | ) 40 | 41 | func SetLogger(log ILogger) { 42 | xlog = log 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | .idea 16 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR:\src\github.com\fananchong\gomap\=\% 3 | set GOPATH=%BASEDIR% 4 | set GOBIN=%CURDIR%\bin 5 | go install ./... 6 | pause -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/element.go: -------------------------------------------------------------------------------- 1 | package gomap 2 | 3 | type Element struct { 4 | key interface{} 5 | val interface{} 6 | pos int 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/iterator.go: -------------------------------------------------------------------------------- 1 | package gomap 2 | 3 | type Iterator struct { 4 | data []*Element 5 | index int 6 | } 7 | 8 | func (i *Iterator) HasNext() bool { 9 | return i.index < len(i.data) 10 | } 11 | 12 | func (i *Iterator) Next() (key, val interface{}) { 13 | tempindex := i.index 14 | i.index++ 15 | return i.data[tempindex].key, i.data[tempindex].val 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/map_base.go: -------------------------------------------------------------------------------- 1 | package gomap 2 | 3 | type MapBase struct { 4 | m map[interface{}]*Element 5 | s []*Element 6 | } 7 | 8 | func (this *MapBase) Init() { 9 | this.m = make(map[interface{}]*Element) 10 | this.s = make([]*Element, 0) 11 | } 12 | 13 | func (this *MapBase) Get(key interface{}) (interface{}, bool) { 14 | if elem, ok := this.m[key]; ok { 15 | if elem.key != key { 16 | panic("[MapBase.Get] DATA ERROR!") 17 | } 18 | return elem.val, true 19 | } 20 | return nil, false 21 | } 22 | 23 | func (this *MapBase) Set(key interface{}, val interface{}) bool { 24 | change := true 25 | if elem, ok := this.m[key]; ok { 26 | if elem.key != key { 27 | panic("[MapBase.Set] DATA ERROR!") 28 | } 29 | if elem.val != val { 30 | elem.val = val 31 | } else { 32 | change = false 33 | } 34 | } else { 35 | elem := &Element{key, val, len(this.s)} 36 | this.m[key] = elem 37 | this.s = append(this.s, elem) 38 | } 39 | return change 40 | } 41 | 42 | func (this *MapBase) Delete(key interface{}) { 43 | if elem, ok := this.m[key]; ok { 44 | if elem.key != key { 45 | panic("[MapBase.Delete] DATA ERROR!") 46 | } 47 | if elem.pos < len(this.s) { 48 | this.s = append(this.s[:elem.pos], this.s[elem.pos+1:]...) 49 | for i := elem.pos + 1; i < len(this.s); i++ { 50 | this.s[i].pos = i 51 | } 52 | } 53 | delete(this.m, key) 54 | } 55 | } 56 | 57 | func (this *MapBase) Iterator() *Iterator { 58 | return &Iterator{ 59 | data: this.s, 60 | index: 0, 61 | } 62 | } 63 | 64 | func (this *MapBase) Count() int { 65 | return len(this.s) 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/ordered_map.go: -------------------------------------------------------------------------------- 1 | package gomap 2 | 3 | import ( 4 | "sort" 5 | ) 6 | 7 | type OrderedMap struct { 8 | MapBase 9 | less func(v1, v2 interface{}) bool 10 | } 11 | 12 | func NewOrderedMap(less func(v1, v2 interface{}) bool) *OrderedMap { 13 | this := &OrderedMap{less: less} 14 | this.Init() 15 | return this 16 | } 17 | 18 | func (this *OrderedMap) Set(key interface{}, val interface{}) bool { 19 | needSort := this.MapBase.Set(key, val) 20 | if needSort { 21 | sort.Sort(this) 22 | } 23 | return needSort 24 | } 25 | 26 | func (this *OrderedMap) First() (key, val interface{}, ok bool) { 27 | if len(this.s) <= 0 { 28 | return nil, nil, false 29 | } 30 | elem := this.s[0] 31 | return elem.key, elem.val, true 32 | } 33 | 34 | func (this *OrderedMap) Back() (key, val interface{}, ok bool) { 35 | len := len(this.s) 36 | if len <= 0 { 37 | return nil, nil, false 38 | } 39 | elem := this.s[len-1] 40 | return elem.key, elem.val, true 41 | } 42 | 43 | func (this *OrderedMap) Len() int { 44 | return len(this.s) 45 | } 46 | 47 | func (this *OrderedMap) Swap(i, j int) { 48 | tempk := this.s[i].key 49 | tempv := this.s[i].val 50 | this.s[i].pos = i 51 | this.s[i].key = this.s[j].key 52 | this.s[i].val = this.s[j].val 53 | this.s[j].pos = j 54 | this.s[j].key = tempk 55 | this.s[j].val = tempv 56 | this.m[this.s[i].key] = this.s[i] 57 | this.m[this.s[j].key] = this.s[j] 58 | } 59 | 60 | func (this *OrderedMap) Less(i, j int) bool { 61 | return this.less(this.s[i].val, this.s[j].val) 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/random_map.go: -------------------------------------------------------------------------------- 1 | package gomap 2 | 3 | import "math/rand" 4 | 5 | type RandomMap struct { 6 | MapBase 7 | } 8 | 9 | func NewRandomMap() *RandomMap { 10 | this := &RandomMap{} 11 | this.Init() 12 | return this 13 | } 14 | 15 | func (this *RandomMap) Random() (key, val interface{}, ok bool) { 16 | len := len(this.s) 17 | if len <= 0 { 18 | return nil, nil, false 19 | } 20 | index := rand.Intn(len) 21 | return this.s[index].key, this.s[index].val, true 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gomap/roundrobin_map.go: -------------------------------------------------------------------------------- 1 | package gomap 2 | 3 | type RoundRobinMap struct { 4 | MapBase 5 | curIndex int 6 | } 7 | 8 | func NewRoundRobinMap() *RoundRobinMap { 9 | this := &RoundRobinMap{} 10 | this.Init() 11 | return this 12 | } 13 | 14 | func (this *RoundRobinMap) RoundRobin() (key, val interface{}, ok bool) { 15 | len := len(this.s) 16 | if len <= 0 { 17 | return nil, nil, false 18 | } 19 | if this.curIndex >= len { 20 | this.curIndex = 0 21 | } 22 | index := this.curIndex 23 | this.curIndex++ 24 | return this.s[index].key, this.s[index].val, true 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR:\src\github.com\fananchong\goredis\=\% 3 | set GOPATH=%BASEDIR% 4 | set GOBIN=%CURDIR%\bin 5 | go install -race ./... 6 | pause -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | docker run --rm -e GOBIN=/go/bin/ -v "$PWD"/bin:/go/bin/ -v "$PWD":/go/src/github.com/fananchong/goredis -w /go/src/github.com/fananchong/goredis golang go install ./... 6 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/cluster.go: -------------------------------------------------------------------------------- 1 | package goredis 2 | 3 | import ( 4 | "errors" 5 | "time" 6 | 7 | "github.com/gomodule/redigo/redis" 8 | "github.com/mna/redisc" 9 | ) 10 | 11 | type ClusterClient struct { 12 | cli *redisc.Cluster 13 | dbName string 14 | option *Option 15 | } 16 | 17 | func NewClusterClient(dbName string, addrs []string, option *Option) (*ClusterClient, error) { 18 | cli := &ClusterClient{} 19 | err := cli.Init(dbName, addrs, option) 20 | return cli, err 21 | } 22 | 23 | func (this *ClusterClient) Init(dbName string, addrs []string, option *Option) error { 24 | this.dbName = dbName 25 | this.option = option 26 | this.cli = &redisc.Cluster{ 27 | StartupNodes: addrs, 28 | DialOptions: []redis.DialOption{redis.DialConnectTimeout(5 * time.Second)}, 29 | CreatePool: this.createPool, 30 | } 31 | if err := this.cli.Refresh(); err != nil { 32 | return err 33 | } 34 | return nil 35 | } 36 | 37 | func (this *ClusterClient) createPool(addr string, options ...redis.DialOption) (*redis.Pool, error) { 38 | return &redis.Pool{ 39 | MaxIdle: this.option.PoolMaxIdle, 40 | MaxActive: this.option.PoolMaxActive, 41 | Wait: this.option.PoolWait, 42 | IdleTimeout: this.option.PoolIdleTimeout, 43 | Dial: func() (redis.Conn, error) { 44 | c, err := redis.Dial("tcp", addr, options...) 45 | if err != nil { 46 | return nil, err 47 | } 48 | if this.option.Password != "" { 49 | if _, err := c.Do("AUTH", this.option.Password); err != nil { 50 | c.Close() 51 | return nil, err 52 | } 53 | } 54 | if _, err := c.Do("SELECT", this.option.DBIndex); err != nil { 55 | c.Close() 56 | return nil, err 57 | } 58 | return c, nil 59 | }, 60 | TestOnBorrow: func(c redis.Conn, t time.Time) error { 61 | _, err := c.Do("PING") 62 | return err 63 | }, 64 | }, nil 65 | } 66 | 67 | func (this *ClusterClient) Do(commandName string, args ...interface{}) (reply interface{}, err error) { 68 | conn := this.cli.Get() 69 | if conn != nil { 70 | defer conn.Close() 71 | return conn.Do(commandName, args...) 72 | } else { 73 | return nil, errors.New("[redis] Can't get redis conn!") 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/option.go: -------------------------------------------------------------------------------- 1 | package goredis 2 | 3 | import "time" 4 | 5 | type RedisType int 6 | 7 | const ( 8 | Unknow RedisType = iota 9 | Standalone 10 | Sentinel 11 | Cluster 12 | ) 13 | 14 | type Option struct { 15 | Type RedisType 16 | Password string 17 | DBIndex int 18 | PoolMaxIdle int 19 | PoolMaxActive int 20 | PoolWait bool 21 | PoolIdleTimeout time.Duration 22 | } 23 | 24 | func NewDefaultOption() *Option { 25 | return &Option{ 26 | Type: Unknow, 27 | Password: "", 28 | DBIndex: 0, 29 | PoolMaxIdle: 10, 30 | PoolMaxActive: 0, 31 | PoolWait: true, 32 | PoolIdleTimeout: 240 * time.Second, 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/redis.go: -------------------------------------------------------------------------------- 1 | package goredis 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | 7 | "github.com/gomodule/redigo/redis" 8 | ) 9 | 10 | type IClient interface { 11 | Do(commandName string, args ...interface{}) (reply interface{}, err error) 12 | } 13 | 14 | type Client struct { 15 | cli IClient 16 | } 17 | 18 | func NewClient(dbName string, addrs []string, option *Option) (*Client, error) { 19 | this := &Client{} 20 | err := this.Init(dbName, addrs, option) 21 | return this, err 22 | } 23 | 24 | func (this *Client) Init(dbName string, addrs []string, option *Option) error { 25 | var err error = nil 26 | if len(addrs) <= 0 { 27 | return errors.New("addrs len error!") 28 | } 29 | switch option.Type { 30 | case Unknow: 31 | { 32 | var conn redis.Conn 33 | var isSentinel, isCluster string 34 | conn, err = getTempConn(addrs[0], option.Password) 35 | if err != nil { 36 | return err 37 | } 38 | defer conn.Close() 39 | isSentinel, err = redis.String(conn.Do("INFO", "Sentinel")) 40 | if err != nil { 41 | return err 42 | } 43 | isCluster, err = redis.String(conn.Do("INFO", "Cluster")) 44 | if err != nil { 45 | return err 46 | } 47 | 48 | if isSentinel != "" { 49 | this.cli = NewSentinelClient(dbName, addrs, option) 50 | } else { 51 | if strings.Contains(isCluster, "0") { 52 | this.cli = NewStandaloneClient(dbName, addrs[0], option) 53 | } else { 54 | this.cli, err = NewClusterClient(dbName, addrs, option) 55 | } 56 | } 57 | } 58 | case Standalone: 59 | { 60 | this.cli = NewStandaloneClient(dbName, addrs[0], option) 61 | } 62 | case Sentinel: 63 | { 64 | this.cli = NewSentinelClient(dbName, addrs, option) 65 | } 66 | case Cluster: 67 | { 68 | this.cli, err = NewClusterClient(dbName, addrs, option) 69 | } 70 | } 71 | return err 72 | } 73 | 74 | func (this *Client) Do(commandName string, args ...interface{}) (reply interface{}, err error) { 75 | return this.cli.Do(commandName, args...) 76 | } 77 | 78 | func getTempConn(addr string, password string) (redis.Conn, error) { 79 | c, err := redis.Dial("tcp", addr) 80 | if err != nil { 81 | return nil, err 82 | } 83 | if password != "" { 84 | if _, err := c.Do("AUTH", password); err != nil { 85 | c.Close() 86 | return nil, err 87 | } 88 | } 89 | return c, nil 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/sentinel.go: -------------------------------------------------------------------------------- 1 | package goredis 2 | 3 | import ( 4 | "errors" 5 | "time" 6 | 7 | "github.com/FZambia/sentinel" 8 | "github.com/gomodule/redigo/redis" 9 | ) 10 | 11 | type SentinelClient struct { 12 | masters *redis.Pool 13 | masterName string 14 | } 15 | 16 | func NewSentinelClient(masterName string, addrs []string, option *Option) *SentinelClient { 17 | cli := &SentinelClient{} 18 | cli.Init(masterName, addrs, option) 19 | return cli 20 | } 21 | 22 | func (this *SentinelClient) Init(masterName string, addrs []string, option *Option) { 23 | sntnl := &sentinel.Sentinel{ 24 | Addrs: addrs, 25 | MasterName: masterName, 26 | Dial: func(addr string) (redis.Conn, error) { 27 | timeout := 500 * time.Millisecond 28 | c, err := redis.DialTimeout("tcp", addr, timeout, timeout, timeout) 29 | if err != nil { 30 | return nil, err 31 | } 32 | return c, nil 33 | }, 34 | } 35 | this.masterName = masterName 36 | this.masters = &redis.Pool{ 37 | MaxIdle: option.PoolMaxIdle, 38 | MaxActive: option.PoolMaxActive, 39 | Wait: option.PoolWait, 40 | IdleTimeout: option.PoolIdleTimeout, 41 | Dial: func() (redis.Conn, error) { 42 | masterAddr, err := sntnl.MasterAddr() 43 | if err != nil { 44 | return nil, err 45 | } 46 | c, err := redis.Dial("tcp", masterAddr) 47 | if err != nil { 48 | return nil, err 49 | } 50 | if option.Password != "" { 51 | if _, err := c.Do("AUTH", option.Password); err != nil { 52 | c.Close() 53 | return nil, err 54 | } 55 | } 56 | if _, err := c.Do("SELECT", option.DBIndex); err != nil { 57 | c.Close() 58 | return nil, err 59 | } 60 | return c, nil 61 | }, 62 | TestOnBorrow: func(c redis.Conn, t time.Time) error { 63 | if !sentinel.TestRole(c, "master") { 64 | return errors.New("[redis] Role check failed") 65 | } else { 66 | return nil 67 | } 68 | }, 69 | } 70 | } 71 | 72 | func (this *SentinelClient) Do(commandName string, args ...interface{}) (reply interface{}, err error) { 73 | conn := this.masters.Get() 74 | if conn != nil { 75 | defer conn.Close() 76 | return conn.Do(commandName, args...) 77 | } else { 78 | return nil, errors.New("[redis] Can't get redis conn!") 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/goredis/standalone.go: -------------------------------------------------------------------------------- 1 | package goredis 2 | 3 | import ( 4 | "errors" 5 | "time" 6 | 7 | "github.com/gomodule/redigo/redis" 8 | ) 9 | 10 | type StandaloneClient struct { 11 | cli *redis.Pool 12 | dbName string 13 | } 14 | 15 | func NewStandaloneClient(dbName string, addr string, option *Option) *StandaloneClient { 16 | cli := &StandaloneClient{} 17 | cli.Init(dbName, addr, option) 18 | return cli 19 | } 20 | 21 | func (this *StandaloneClient) Init(dbName string, addr string, option *Option) { 22 | this.dbName = dbName 23 | this.cli = &redis.Pool{ 24 | MaxIdle: option.PoolMaxIdle, 25 | MaxActive: option.PoolMaxActive, 26 | Wait: option.PoolWait, 27 | IdleTimeout: option.PoolIdleTimeout, 28 | Dial: func() (redis.Conn, error) { 29 | c, err := redis.Dial("tcp", addr) 30 | if err != nil { 31 | return nil, err 32 | } 33 | if option.Password != "" { 34 | if _, err := c.Do("AUTH", option.Password); err != nil { 35 | c.Close() 36 | return nil, err 37 | } 38 | } 39 | if _, err := c.Do("SELECT", option.DBIndex); err != nil { 40 | c.Close() 41 | return nil, err 42 | } 43 | return c, nil 44 | }, 45 | TestOnBorrow: func(c redis.Conn, t time.Time) error { 46 | _, err := c.Do("PING") 47 | return err 48 | }, 49 | } 50 | } 51 | 52 | func (this *StandaloneClient) Do(commandName string, args ...interface{}) (reply interface{}, err error) { 53 | conn := this.cli.Get() 54 | if conn != nil { 55 | defer conn.Close() 56 | return conn.Do(commandName, args...) 57 | } else { 58 | return nil, errors.New("[redis] Can't get redis conn!") 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | /bin 16 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/build"] 2 | path = tools/build 3 | url = https://github.com/fananchong/my_build_tools.git 4 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 fananchong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/README.md: -------------------------------------------------------------------------------- 1 | # gotcp 2 | 3 | 一个GO语言TCP网络库 4 | 5 | ## 服务器例子 6 | 7 | 1. 组合嵌入gotcp.Session,制作自己的TCP网络会话 8 | 9 | 例如: 10 | 11 | ```go 12 | type Echo struct { 13 | gotcp.Session 14 | } 15 | 16 | func (this *Echo) OnRecv(data []byte, flag byte) { 17 | if this.IsVerified() == false { 18 | // ...(业务代码,略)... 19 | this.Verify() 20 | } 21 | // ...(业务代码,略)... 22 | } 23 | 24 | func (this *Echo) OnClose() { 25 | // ...(业务代码,略)... 26 | } 27 | ``` 28 | 29 | 2. 注册网络会话类,开启服务 30 | 31 | 例如: 32 | 33 | ```go 34 | s := &gotcp.Server{} 35 | s.RegisterSessType(Echo{}) 36 | s.Start(":3000") 37 | ``` 38 | 39 | ## 客户端例子 40 | 41 | 1. 组合嵌入gotcp.Session,制作自己的TCP网络会话 42 | 43 | 例如: 44 | 45 | ```go 46 | type Echo struct { 47 | gotcp.Session 48 | } 49 | 50 | func (this *Echo) OnRecv(data []byte, flag byte) { 51 | if this.IsVerified() == false { 52 | // ...(业务代码,略)... 53 | this.Verify() 54 | } 55 | // ...(业务代码,略)... 56 | } 57 | 58 | func (this *Echo) OnClose() { 59 | // ...(业务代码,略)... 60 | } 61 | ``` 62 | 63 | 2. 连接服务器 64 | 65 | 例如: 66 | 67 | ```go 68 | echo := &Echo{} 69 | echo.Connect("localhost:3000", echo) 70 | ``` 71 | 72 | ## 参考项目 73 | 74 | 参考了以下开源库: 75 | 76 | - 77 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/build.bat: -------------------------------------------------------------------------------- 1 | set CURDIR=%~dp0 2 | set BASEDIR=%CURDIR:\src\github.com\fananchong\gotcp\=\% 3 | set GOPATH=%BASEDIR% 4 | set GOBIN=%CURDIR%\bin 5 | go install -race ./... 6 | pause -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/client.go: -------------------------------------------------------------------------------- 1 | package gotcp 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | func (this *Session) Connect(address string, derived ISession) bool { 9 | if this.IsClosed() == false { 10 | xlog.Errorln("close session. server address =", this.RemoteAddr()) 11 | this.Close() 12 | } 13 | conn, err := connectDetail(address) 14 | if err == nil { 15 | this.Init(conn, nil, derived) 16 | this.Start() 17 | xlog.Infoln("connect server success. server address =", this.RemoteAddr()) 18 | return true 19 | } else { 20 | xlog.Errorln(err) 21 | return false 22 | } 23 | } 24 | 25 | func connectDetail(address string) (*net.TCPConn, error) { 26 | tcpAddr, err := net.ResolveTCPAddr("tcp4", address) 27 | if err != nil { 28 | return nil, err 29 | } 30 | conn, err := net.DialTCP("tcp", nil, tcpAddr) 31 | if err != nil { 32 | return nil, err 33 | } 34 | conn.SetKeepAlive(true) 35 | conn.SetKeepAlivePeriod(1 * time.Minute) 36 | conn.SetNoDelay(true) 37 | conn.SetWriteBuffer(128 * 1024) 38 | conn.SetReadBuffer(128 * 1024) 39 | return conn, nil 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/log.go: -------------------------------------------------------------------------------- 1 | package gotcp 2 | 3 | import "fmt" 4 | 5 | type ILogger interface { 6 | Info(args ...interface{}) 7 | Infoln(args ...interface{}) 8 | Infof(format string, args ...interface{}) 9 | Error(args ...interface{}) 10 | Errorln(args ...interface{}) 11 | Errorf(format string, args ...interface{}) 12 | } 13 | 14 | type DefaultLogger struct { 15 | } 16 | 17 | func NewDefaultLogger() *DefaultLogger { 18 | return &DefaultLogger{} 19 | } 20 | 21 | func (this *DefaultLogger) Info(args ...interface{}) { 22 | fmt.Print(args...) 23 | } 24 | 25 | func (this *DefaultLogger) Infoln(args ...interface{}) { 26 | fmt.Println(args...) 27 | } 28 | 29 | func (this *DefaultLogger) Infof(format string, args ...interface{}) { 30 | fmt.Printf(format, args...) 31 | } 32 | 33 | func (this *DefaultLogger) Error(args ...interface{}) { 34 | fmt.Print(args...) 35 | } 36 | 37 | func (this *DefaultLogger) Errorln(args ...interface{}) { 38 | fmt.Println(args...) 39 | } 40 | 41 | func (this *DefaultLogger) Errorf(format string, args ...interface{}) { 42 | fmt.Printf(format, args...) 43 | } 44 | 45 | var ( 46 | xlog ILogger = NewDefaultLogger() 47 | ) 48 | 49 | func SetLogger(log ILogger) { 50 | xlog = log 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/server.go: -------------------------------------------------------------------------------- 1 | package gotcp 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "reflect" 7 | "time" 8 | ) 9 | 10 | type Server struct { 11 | listener *net.TCPListener 12 | sessType reflect.Type 13 | ctx context.Context 14 | ctxCancel context.CancelFunc 15 | address string 16 | } 17 | 18 | func (this *Server) RegisterSessType(v interface{}) { 19 | this.sessType = reflect.ValueOf(v).Type() 20 | } 21 | 22 | func (this *Server) Start(address string) bool { 23 | this.address = address 24 | if this.listener != nil { 25 | return true 26 | } 27 | err := this.bind(address) 28 | if err != nil { 29 | xlog.Errorln(err) 30 | return false 31 | } 32 | xlog.Infoln("start listen", address) 33 | this.ctx, this.ctxCancel = context.WithCancel(context.Background()) 34 | go this.loop() 35 | return true 36 | } 37 | 38 | func (this *Server) Close() { 39 | this.ctxCancel() 40 | this.listener.Close() 41 | this.listener = nil 42 | } 43 | 44 | func (this *Server) loop() { 45 | for { 46 | select { 47 | case <-this.ctx.Done(): 48 | xlog.Infoln("server close. address =", this.address) 49 | return 50 | default: 51 | conn, err := this.accept() 52 | if err == nil { 53 | sess := reflect.New(this.sessType) 54 | f := sess.MethodByName("Init") 55 | f.Call([]reflect.Value{reflect.ValueOf(conn), reflect.ValueOf(this.ctx), sess}) 56 | f = sess.MethodByName("Start") 57 | f.Call([]reflect.Value{}) 58 | f = sess.MethodByName("RemoteAddr") 59 | addr := f.Call([]reflect.Value{}) 60 | xlog.Infoln("connect come in. client address =", addr) 61 | } 62 | } 63 | } 64 | } 65 | 66 | func (this *Server) bind(address string) error { 67 | tcpAddr, err := net.ResolveTCPAddr("tcp4", address) 68 | if err != nil { 69 | return err 70 | } 71 | listener, err := net.ListenTCP("tcp", tcpAddr) 72 | if err != nil { 73 | return err 74 | } 75 | this.listener = listener 76 | return nil 77 | } 78 | 79 | func (this *Server) accept() (*net.TCPConn, error) { 80 | conn, err := this.listener.AcceptTCP() 81 | if err != nil { 82 | if opErr, ok := err.(*net.OpError); ok && !opErr.Timeout() { 83 | xlog.Errorln(err) 84 | } 85 | return nil, err 86 | } 87 | conn.SetKeepAlive(true) 88 | conn.SetKeepAlivePeriod(1 * time.Minute) 89 | conn.SetNoDelay(true) 90 | conn.SetWriteBuffer(128 * 1024) 91 | conn.SetReadBuffer(128 * 1024) 92 | return conn, nil 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/session_protomsg.go: -------------------------------------------------------------------------------- 1 | package gotcp 2 | 3 | import ( 4 | "github.com/golang/protobuf/proto" 5 | ) 6 | 7 | func (this *Session) SendMsg(cmd uint64, msg proto.Message) bool { 8 | data, flag, err := EncodeCmd(cmd, msg) 9 | if err != nil { 10 | return false 11 | } 12 | return this.Send(data, flag) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/gotcp/util.go: -------------------------------------------------------------------------------- 1 | package gotcp 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | func GetVaildPort(showmsg bool) int { 9 | port := 10000 10 | for { 11 | port = port + 1 12 | address := fmt.Sprintf(":%d", port) 13 | tcpAddr, err := net.ResolveTCPAddr("tcp4", address) 14 | if err != nil { 15 | if showmsg { 16 | xlog.Errorln(err) 17 | } 18 | continue 19 | } 20 | listener, err := net.ListenTCP("tcp", tcpAddr) 21 | if err != nil { 22 | if showmsg { 23 | xlog.Errorln(err) 24 | } 25 | if listener != nil { 26 | listener.Close() 27 | } 28 | continue 29 | } 30 | listener.Close() 31 | return port 32 | } 33 | return 0 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | 25 | *~ 26 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 1.3 3 | script: go test ./... 4 | 5 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Koding, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/doc.go: -------------------------------------------------------------------------------- 1 | // Package multiconfig provides a way to load and read configurations from 2 | // multiple sources. You can read from TOML file, JSON file, YAML file, Environment 3 | // Variables and flags. You can set the order of reader with MultiLoader. Package 4 | // is extensible, you can add your custom Loader by implementing the Load interface. 5 | package multiconfig 6 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/multiloader.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | type multiLoader []Loader 4 | 5 | // MultiLoader creates a loader that executes the loaders one by one in order 6 | // and returns on the first error. 7 | func MultiLoader(loader ...Loader) Loader { 8 | return multiLoader(loader) 9 | } 10 | 11 | // Load loads the source into the config defined by struct s 12 | func (m multiLoader) Load(s interface{}) error { 13 | for _, loader := range m { 14 | if err := loader.Load(s); err != nil { 15 | return err 16 | } 17 | } 18 | 19 | return nil 20 | } 21 | 22 | // MustLoad loads the source into the struct, it panics if gets any error 23 | func (m multiLoader) MustLoad(s interface{}) { 24 | if err := m.Load(s); err != nil { 25 | panic(err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/multivalidator.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | type multiValidator []Validator 4 | 5 | // MultiValidator accepts variadic validators and satisfies Validator interface. 6 | func MultiValidator(validators ...Validator) Validator { 7 | return multiValidator(validators) 8 | } 9 | 10 | // Validate tries to validate given struct with all the validators. If it doesn't 11 | // have any Validator it will simply skip the validation step. If any of the 12 | // given validators return err, it will stop validating and return it. 13 | func (d multiValidator) Validate(s interface{}) error { 14 | for _, validator := range d { 15 | if err := validator.Validate(s); err != nil { 16 | return err 17 | } 18 | } 19 | 20 | return nil 21 | } 22 | 23 | // MustValidate validates the struct, it panics if gets any error 24 | func (d multiValidator) MustValidate(s interface{}) { 25 | if err := d.Validate(s); err != nil { 26 | panic(err) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/tag.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | import ( 4 | "reflect" 5 | 6 | "github.com/fatih/structs" 7 | ) 8 | 9 | // TagLoader satisfies the loader interface. It parses a struct's field tags 10 | // and populates the each field with that given tag. 11 | type TagLoader struct { 12 | // DefaultTagName is the default tag name for struct fields to define 13 | // default values for a field. Example: 14 | // 15 | // // Field's default value is "koding". 16 | // Name string `default:"koding"` 17 | // 18 | // The default value is "default" if it's not set explicitly. 19 | DefaultTagName string 20 | } 21 | 22 | func (t *TagLoader) Load(s interface{}) error { 23 | if t.DefaultTagName == "" { 24 | t.DefaultTagName = "default" 25 | } 26 | 27 | for _, field := range structs.Fields(s) { 28 | 29 | if err := t.processField(t.DefaultTagName, field); err != nil { 30 | return err 31 | } 32 | } 33 | 34 | return nil 35 | } 36 | 37 | // processField gets tagName and the field, recursively checks if the field has the given 38 | // tag, if yes, sets it otherwise ignores 39 | func (t *TagLoader) processField(tagName string, field *structs.Field) error { 40 | switch field.Kind() { 41 | case reflect.Struct: 42 | for _, f := range field.Fields() { 43 | if err := t.processField(tagName, f); err != nil { 44 | return err 45 | } 46 | } 47 | default: 48 | defaultVal := field.Tag(t.DefaultTagName) 49 | if defaultVal == "" { 50 | return nil 51 | } 52 | 53 | err := fieldSet(field, defaultVal) 54 | if err != nil { 55 | return err 56 | } 57 | } 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/fananchong/multiconfig/validator.go: -------------------------------------------------------------------------------- 1 | package multiconfig 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "github.com/fatih/structs" 8 | ) 9 | 10 | // Validator validates the config against any predefined rules, those predefined 11 | // rules should be given to this package. The implementer will be responsible 12 | // for the logic. 13 | type Validator interface { 14 | // Validate validates the config struct 15 | Validate(s interface{}) error 16 | } 17 | 18 | // RequiredValidator validates the struct against zero values. 19 | type RequiredValidator struct { 20 | // TagName holds the validator tag name. The default is "required" 21 | TagName string 22 | 23 | // TagValue holds the expected value of the validator. The default is "true" 24 | TagValue string 25 | } 26 | 27 | // Validate validates the given struct agaist field's zero values. If 28 | // intentionaly, the value of a field is `zero-valued`(e.g false, 0, "") 29 | // required tag should not be set for that field. 30 | func (e *RequiredValidator) Validate(s interface{}) error { 31 | if e.TagName == "" { 32 | e.TagName = "required" 33 | } 34 | 35 | if e.TagValue == "" { 36 | e.TagValue = "true" 37 | } 38 | 39 | for _, field := range structs.Fields(s) { 40 | if err := e.processField("", field); err != nil { 41 | return err 42 | } 43 | } 44 | 45 | return nil 46 | } 47 | 48 | func (e *RequiredValidator) processField(fieldName string, field *structs.Field) error { 49 | fieldName += field.Name() 50 | switch field.Kind() { 51 | case reflect.Struct: 52 | // this is used for error messages below, when we have an error at the 53 | // child properties add parent properties into the error message as well 54 | fieldName += "." 55 | 56 | for _, f := range field.Fields() { 57 | if err := e.processField(fieldName, f); err != nil { 58 | return err 59 | } 60 | } 61 | default: 62 | val := field.Tag(e.TagName) 63 | if val != e.TagValue { 64 | return nil 65 | } 66 | 67 | if field.IsZero() { 68 | return fmt.Errorf("multiconfig: field '%s' is required", fieldName) 69 | } 70 | } 71 | 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/camelcase/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 1.x 3 | 4 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/camelcase/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Fatih Arslan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.7.x 4 | - 1.8.x 5 | - 1.9.x 6 | - tip 7 | sudo: false 8 | before_install: 9 | - go get github.com/axw/gocov/gocov 10 | - go get github.com/mattn/goveralls 11 | - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi 12 | script: 13 | - $HOME/gopath/bin/goveralls -service=travis-ci 14 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Fatih Arslan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/tags.go: -------------------------------------------------------------------------------- 1 | package structs 2 | 3 | import "strings" 4 | 5 | // tagOptions contains a slice of tag options 6 | type tagOptions []string 7 | 8 | // Has returns true if the given option is available in tagOptions 9 | func (t tagOptions) Has(opt string) bool { 10 | for _, tagOpt := range t { 11 | if tagOpt == opt { 12 | return true 13 | } 14 | } 15 | 16 | return false 17 | } 18 | 19 | // parseTag splits a struct field's tag into its name and a list of options 20 | // which comes after a name. A tag is in the form of: "name,option1,option2". 21 | // The name can be neglectected. 22 | func parseTag(tag string) (string, tagOptions) { 23 | // tag is one of followings: 24 | // "" 25 | // "name" 26 | // "name,opt" 27 | // "name,opt,opt2" 28 | // ",opt" 29 | 30 | res := strings.Split(tag, ",") 31 | return res[0], res[1:] 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/gogo/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of GoGo authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS file, which 3 | # lists people. For example, employees are listed in CONTRIBUTORS, 4 | # but not in AUTHORS, because the employer holds the copyright. 5 | 6 | # Names should be added to this file as one of 7 | # Organization's name 8 | # Individual's name 9 | # Individual's name 10 | 11 | # Please keep the list sorted. 12 | 13 | Sendgrid, Inc 14 | Vastech SA (PTY) LTD 15 | Walter Schulze 16 | -------------------------------------------------------------------------------- /vendor/github.com/gogo/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Anton Povarov 2 | Brian Goff 3 | Clayton Coleman 4 | Denis Smirnov 5 | DongYun Kang 6 | Dwayne Schultz 7 | Georg Apitz 8 | Gustav Paul 9 | Johan Brandhorst 10 | John Shahid 11 | John Tuley 12 | Laurent 13 | Patrick Lee 14 | Peter Edge 15 | Roger Johansson 16 | Sam Nguyen 17 | Sergio Arbeo 18 | Stephen J Day 19 | Tamir Duberstein 20 | Todd Eisenberger 21 | Tormod Erevik Lea 22 | Vyacheslav Kim 23 | Walter Schulze 24 | -------------------------------------------------------------------------------- /vendor/github.com/gogo/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Protocol Buffers for Go with Gadgets 2 | 3 | Copyright (c) 2013, The GoGo Authors. All rights reserved. 4 | http://github.com/gogo/protobuf 5 | 6 | Go support for Protocol Buffers - Google's data interchange format 7 | 8 | Copyright 2010 The Go Authors. All rights reserved. 9 | https://github.com/golang/protobuf 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above 18 | copyright notice, this list of conditions and the following disclaimer 19 | in the documentation and/or other materials provided with the 20 | distribution. 21 | * Neither the name of Google Inc. nor the names of its 22 | contributors may be used to endorse or promote products derived from 23 | this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | -------------------------------------------------------------------------------- /vendor/github.com/gogo/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc-min-version --version="3.0.0" --proto_path=.:../../../../:../protobuf --gogo_out=Mtestdata/test.proto=github.com/gogo/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /vendor/github.com/gogo/protobuf/proto/lib_gogo.go: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Go with Gadgets 2 | // 3 | // Copyright (c) 2013, The GoGo Authors. All rights reserved. 4 | // http://github.com/gogo/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package proto 30 | 31 | import ( 32 | "encoding/json" 33 | "strconv" 34 | ) 35 | 36 | func MarshalJSONEnum(m map[int32]string, value int32) ([]byte, error) { 37 | s, ok := m[value] 38 | if !ok { 39 | s = strconv.Itoa(int(value)) 40 | } 41 | return json.Marshal(s) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/gogo/protobuf/proto/text_gogo.go: -------------------------------------------------------------------------------- 1 | // Protocol Buffers for Go with Gadgets 2 | // 3 | // Copyright (c) 2013, The GoGo Authors. All rights reserved. 4 | // http://github.com/gogo/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | package proto 30 | 31 | import ( 32 | "fmt" 33 | "reflect" 34 | ) 35 | 36 | func (tm *TextMarshaler) writeEnum(w *textWriter, v reflect.Value, props *Properties) error { 37 | m, ok := enumStringMaps[props.Enum] 38 | if !ok { 39 | if err := tm.writeAny(w, v, props); err != nil { 40 | return err 41 | } 42 | } 43 | key := int32(0) 44 | if v.Kind() == reflect.Ptr { 45 | key = int32(v.Elem().Int()) 46 | } else { 47 | key = int32(v.Int()) 48 | } 49 | s, ok := m[key] 50 | if !ok { 51 | if err := tm.writeAny(w, v, props); err != nil { 52 | return err 53 | } 54 | } 55 | _, err := fmt.Fprint(w, s) 56 | return err 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /vendor/github.com/gomodule/redigo/internal/commandinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package internal 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | const ( 22 | WatchState = 1 << iota 23 | MultiState 24 | SubscribeState 25 | MonitorState 26 | ) 27 | 28 | type CommandInfo struct { 29 | Set, Clear int 30 | } 31 | 32 | var commandInfos = map[string]CommandInfo{ 33 | "WATCH": {Set: WatchState}, 34 | "UNWATCH": {Clear: WatchState}, 35 | "MULTI": {Set: MultiState}, 36 | "EXEC": {Clear: WatchState | MultiState}, 37 | "DISCARD": {Clear: WatchState | MultiState}, 38 | "PSUBSCRIBE": {Set: SubscribeState}, 39 | "SUBSCRIBE": {Set: SubscribeState}, 40 | "MONITOR": {Set: MonitorState}, 41 | } 42 | 43 | func init() { 44 | for n, ci := range commandInfos { 45 | commandInfos[strings.ToLower(n)] = ci 46 | } 47 | } 48 | 49 | func LookupCommandInfo(commandName string) CommandInfo { 50 | if ci, ok := commandInfos[commandName]; ok { 51 | return ci 52 | } 53 | return commandInfos[strings.ToUpper(commandName)] 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/gomodule/redigo/redis/go16.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package redis 4 | 5 | import "crypto/tls" 6 | 7 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 8 | return &tls.Config{ 9 | Rand: cfg.Rand, 10 | Time: cfg.Time, 11 | Certificates: cfg.Certificates, 12 | NameToCertificate: cfg.NameToCertificate, 13 | GetCertificate: cfg.GetCertificate, 14 | RootCAs: cfg.RootCAs, 15 | NextProtos: cfg.NextProtos, 16 | ServerName: cfg.ServerName, 17 | ClientAuth: cfg.ClientAuth, 18 | ClientCAs: cfg.ClientCAs, 19 | InsecureSkipVerify: cfg.InsecureSkipVerify, 20 | CipherSuites: cfg.CipherSuites, 21 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 22 | ClientSessionCache: cfg.ClientSessionCache, 23 | MinVersion: cfg.MinVersion, 24 | MaxVersion: cfg.MaxVersion, 25 | CurvePreferences: cfg.CurvePreferences, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/gomodule/redigo/redis/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7,!go1.8 2 | 3 | package redis 4 | 5 | import "crypto/tls" 6 | 7 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 8 | return &tls.Config{ 9 | Rand: cfg.Rand, 10 | Time: cfg.Time, 11 | Certificates: cfg.Certificates, 12 | NameToCertificate: cfg.NameToCertificate, 13 | GetCertificate: cfg.GetCertificate, 14 | RootCAs: cfg.RootCAs, 15 | NextProtos: cfg.NextProtos, 16 | ServerName: cfg.ServerName, 17 | ClientAuth: cfg.ClientAuth, 18 | ClientCAs: cfg.ClientCAs, 19 | InsecureSkipVerify: cfg.InsecureSkipVerify, 20 | CipherSuites: cfg.CipherSuites, 21 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 22 | ClientSessionCache: cfg.ClientSessionCache, 23 | MinVersion: cfg.MinVersion, 24 | MaxVersion: cfg.MaxVersion, 25 | CurvePreferences: cfg.CurvePreferences, 26 | DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled, 27 | Renegotiation: cfg.Renegotiation, 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/gomodule/redigo/redis/go18.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | package redis 4 | 5 | import "crypto/tls" 6 | 7 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 8 | return cfg.Clone() 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/gomodule/redigo/redis/pool17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | // +build go1.7 16 | 17 | package redis 18 | 19 | import "context" 20 | 21 | // GetContext gets a connection using the provided context. 22 | // 23 | // The provided Context must be non-nil. If the context expires before the 24 | // connection is complete, an error is returned. Any expiration on the context 25 | // will not affect the returned connection. 26 | // 27 | // If the function completes without error, then the application must close the 28 | // returned connection. 29 | func (p *Pool) GetContext(ctx context.Context) (Conn, error) { 30 | pc, err := p.get(ctx) 31 | if err != nil { 32 | return errorConn{err}, err 33 | } 34 | return &activeConn{p: p, pc: pc}, nil 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/mna/redisc/.gitignore: -------------------------------------------------------------------------------- 1 | # cover/profile output files 2 | *.out 3 | 4 | # test binaries 5 | *.test 6 | 7 | 8 | -------------------------------------------------------------------------------- /vendor/github.com/mna/redisc/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Martin Angers 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /vendor/github.com/mna/redisc/hash.go: -------------------------------------------------------------------------------- 1 | package redisc 2 | 3 | import ( 4 | "sort" 5 | "strings" 6 | ) 7 | 8 | // Slot returns the hash slot for the key. 9 | func Slot(key string) int { 10 | if start := strings.Index(key, "{"); start >= 0 { 11 | if end := strings.Index(key[start+1:], "}"); end > 0 { // if end == 0, then it's {}, so we ignore it 12 | end += start + 1 13 | key = key[start+1 : end] 14 | } 15 | } 16 | return int(crc16(key) % hashSlots) 17 | } 18 | 19 | // SplitBySlot takes a list of keys and returns a list of list of keys, 20 | // grouped by identical cluster slot. For example: 21 | // 22 | // bySlot := SplitBySlot("k1", "k2", "k3") 23 | // for _, keys := range bySlot { 24 | // // keys is a list of keys that belong to the same slot 25 | // } 26 | func SplitBySlot(keys ...string) [][]string { 27 | var slots []int 28 | m := make(map[int][]string) 29 | for _, k := range keys { 30 | slot := Slot(k) 31 | _, ok := m[slot] 32 | m[slot] = append(m[slot], k) 33 | 34 | if !ok { 35 | slots = append(slots, slot) 36 | } 37 | } 38 | 39 | sort.Ints(slots) 40 | bySlot := make([][]string, 0, len(m)) 41 | for _, slot := range slots { 42 | bySlot = append(bySlot, m[slot]) 43 | } 44 | return bySlot 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/satori/go.uuid/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | go: 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | - 1.6 9 | - 1.7 10 | - 1.8 11 | - 1.9 12 | - tip 13 | matrix: 14 | allow_failures: 15 | - go: tip 16 | fast_finish: true 17 | before_install: 18 | - go get github.com/mattn/goveralls 19 | - go get golang.org/x/tools/cmd/cover 20 | script: 21 | - $HOME/gopath/bin/goveralls -service=travis-ci 22 | notifications: 23 | email: false 24 | -------------------------------------------------------------------------------- /vendor/github.com/satori/go.uuid/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013-2018 by Maxim Bublis 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/satori/go.uuid/README.md: -------------------------------------------------------------------------------- 1 | # UUID package for Go language 2 | 3 | [![Build Status](https://travis-ci.org/satori/go.uuid.svg?branch=master)](https://travis-ci.org/satori/go.uuid) 4 | [![Coverage Status](https://coveralls.io/repos/github/satori/go.uuid/badge.svg?branch=master)](https://coveralls.io/github/satori/go.uuid) 5 | [![GoDoc](http://godoc.org/github.com/satori/go.uuid?status.svg)](http://godoc.org/github.com/satori/go.uuid) 6 | 7 | This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs. 8 | 9 | With 100% test coverage and benchmarks out of box. 10 | 11 | Supported versions: 12 | * Version 1, based on timestamp and MAC address (RFC 4122) 13 | * Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1) 14 | * Version 3, based on MD5 hashing (RFC 4122) 15 | * Version 4, based on random numbers (RFC 4122) 16 | * Version 5, based on SHA-1 hashing (RFC 4122) 17 | 18 | ## Installation 19 | 20 | Use the `go` command: 21 | 22 | $ go get github.com/satori/go.uuid 23 | 24 | ## Requirements 25 | 26 | UUID package requires Go >= 1.2. 27 | 28 | ## Example 29 | 30 | ```go 31 | package main 32 | 33 | import ( 34 | "fmt" 35 | "github.com/satori/go.uuid" 36 | ) 37 | 38 | func main() { 39 | // Creating UUID Version 4 40 | // panic on error 41 | u1 := uuid.Must(uuid.NewV4()) 42 | fmt.Printf("UUIDv4: %s\n", u1) 43 | 44 | // or error handling 45 | u2, err := uuid.NewV4() 46 | if err != nil { 47 | fmt.Printf("Something went wrong: %s", err) 48 | return 49 | } 50 | fmt.Printf("UUIDv4: %s\n", u2) 51 | 52 | // Parsing UUID from string input 53 | u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8") 54 | if err != nil { 55 | fmt.Printf("Something went wrong: %s", err) 56 | } 57 | fmt.Printf("Successfully parsed: %s", u2) 58 | } 59 | ``` 60 | 61 | ## Documentation 62 | 63 | [Documentation](http://godoc.org/github.com/satori/go.uuid) is hosted at GoDoc project. 64 | 65 | ## Links 66 | * [RFC 4122](http://tools.ietf.org/html/rfc4122) 67 | * [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01) 68 | 69 | ## Copyright 70 | 71 | Copyright (C) 2013-2018 by Maxim Bublis . 72 | 73 | UUID package released under MIT License. 74 | See [LICENSE](https://github.com/satori/go.uuid/blob/master/LICENSE) for details. 75 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http/httpguts/guts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. 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 httpguts provides functions implementing various details 6 | // of the HTTP specification. 7 | // 8 | // This package is shared by the standard library (which vendors it) 9 | // and x/net/http2. It comes with no API stability promise. 10 | package httpguts 11 | 12 | import ( 13 | "net/textproto" 14 | "strings" 15 | ) 16 | 17 | // ValidTrailerHeader reports whether name is a valid header field name to appear 18 | // in trailers. 19 | // See RFC 7230, Section 4.1.2 20 | func ValidTrailerHeader(name string) bool { 21 | name = textproto.CanonicalMIMEHeaderKey(name) 22 | if strings.HasPrefix(name, "If-") || badTrailer[name] { 23 | return false 24 | } 25 | return true 26 | } 27 | 28 | var badTrailer = map[string]bool{ 29 | "Authorization": true, 30 | "Cache-Control": true, 31 | "Connection": true, 32 | "Content-Encoding": true, 33 | "Content-Length": true, 34 | "Content-Range": true, 35 | "Content-Type": true, 36 | "Expect": true, 37 | "Host": true, 38 | "Keep-Alive": true, 39 | "Max-Forwards": true, 40 | "Pragma": true, 41 | "Proxy-Authenticate": true, 42 | "Proxy-Authorization": true, 43 | "Proxy-Connection": true, 44 | "Range": true, 45 | "Realm": true, 46 | "Te": true, 47 | "Trailer": true, 48 | "Transfer-Encoding": true, 49 | "Www-Authenticate": true, 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | h2i/h2i 3 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # This Dockerfile builds a recent curl with HTTP/2 client support, using 3 | # a recent nghttp2 build. 4 | # 5 | # See the Makefile for how to tag it. If Docker and that image is found, the 6 | # Go tests use this curl binary for integration tests. 7 | # 8 | 9 | FROM ubuntu:trusty 10 | 11 | RUN apt-get update && \ 12 | apt-get upgrade -y && \ 13 | apt-get install -y git-core build-essential wget 14 | 15 | RUN apt-get install -y --no-install-recommends \ 16 | autotools-dev libtool pkg-config zlib1g-dev \ 17 | libcunit1-dev libssl-dev libxml2-dev libevent-dev \ 18 | automake autoconf 19 | 20 | # The list of packages nghttp2 recommends for h2load: 21 | RUN apt-get install -y --no-install-recommends make binutils \ 22 | autoconf automake autotools-dev \ 23 | libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev \ 24 | libev-dev libevent-dev libjansson-dev libjemalloc-dev \ 25 | cython python3.4-dev python-setuptools 26 | 27 | # Note: setting NGHTTP2_VER before the git clone, so an old git clone isn't cached: 28 | ENV NGHTTP2_VER 895da9a 29 | RUN cd /root && git clone https://github.com/tatsuhiro-t/nghttp2.git 30 | 31 | WORKDIR /root/nghttp2 32 | RUN git reset --hard $NGHTTP2_VER 33 | RUN autoreconf -i 34 | RUN automake 35 | RUN autoconf 36 | RUN ./configure 37 | RUN make 38 | RUN make install 39 | 40 | WORKDIR /root 41 | RUN wget http://curl.haxx.se/download/curl-7.45.0.tar.gz 42 | RUN tar -zxvf curl-7.45.0.tar.gz 43 | WORKDIR /root/curl-7.45.0 44 | RUN ./configure --with-ssl --with-nghttp2=/usr/local 45 | RUN make 46 | RUN make install 47 | RUN ldconfig 48 | 49 | CMD ["-h"] 50 | ENTRYPOINT ["/usr/local/bin/curl"] 51 | 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Makefile: -------------------------------------------------------------------------------- 1 | curlimage: 2 | docker build -t gohttp2/curl . 3 | 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/README: -------------------------------------------------------------------------------- 1 | This is a work-in-progress HTTP/2 implementation for Go. 2 | 3 | It will eventually live in the Go standard library and won't require 4 | any changes to your code to use. It will just be automatic. 5 | 6 | Status: 7 | 8 | * The server support is pretty good. A few things are missing 9 | but are being worked on. 10 | * The client work has just started but shares a lot of code 11 | is coming along much quicker. 12 | 13 | Docs are at https://godoc.org/golang.org/x/net/http2 14 | 15 | Demo test server at https://http2.golang.org/ 16 | 17 | Help & bug reports welcome! 18 | 19 | Contributing: https://golang.org/doc/contribute.html 20 | Bugs: https://golang.org/issue/new?title=x/net/http2:+ 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/flow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. 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 | // Flow control 6 | 7 | package http2 8 | 9 | // flow is the flow control window's size. 10 | type flow struct { 11 | // n is the number of DATA bytes we're allowed to send. 12 | // A flow is kept both on a conn and a per-stream. 13 | n int32 14 | 15 | // conn points to the shared connection-level flow that is 16 | // shared by all streams on that conn. It is nil for the flow 17 | // that's on the conn directly. 18 | conn *flow 19 | } 20 | 21 | func (f *flow) setConnFlow(cf *flow) { f.conn = cf } 22 | 23 | func (f *flow) available() int32 { 24 | n := f.n 25 | if f.conn != nil && f.conn.n < n { 26 | n = f.conn.n 27 | } 28 | return n 29 | } 30 | 31 | func (f *flow) take(n int32) { 32 | if n > f.available() { 33 | panic("internal error: took too much") 34 | } 35 | f.n -= n 36 | if f.conn != nil { 37 | f.conn.n -= n 38 | } 39 | } 40 | 41 | // add adds n bytes (positive or negative) to the flow control window. 42 | // It returns false if the sum would exceed 2^31-1. 43 | func (f *flow) add(n int32) bool { 44 | sum := f.n + n 45 | if (sum > n) == (f.n > 0) { 46 | f.n = sum 47 | return true 48 | } 49 | return false 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. 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 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | ) 13 | 14 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 15 | return t1.ExpectContinueTimeout 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go17_not18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. 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 | // +build go1.7,!go1.8 6 | 7 | package http2 8 | 9 | import "crypto/tls" 10 | 11 | // temporary copy of Go 1.7's private tls.Config.clone: 12 | func cloneTLSConfig(c *tls.Config) *tls.Config { 13 | return &tls.Config{ 14 | Rand: c.Rand, 15 | Time: c.Time, 16 | Certificates: c.Certificates, 17 | NameToCertificate: c.NameToCertificate, 18 | GetCertificate: c.GetCertificate, 19 | RootCAs: c.RootCAs, 20 | NextProtos: c.NextProtos, 21 | ServerName: c.ServerName, 22 | ClientAuth: c.ClientAuth, 23 | ClientCAs: c.ClientCAs, 24 | InsecureSkipVerify: c.InsecureSkipVerify, 25 | CipherSuites: c.CipherSuites, 26 | PreferServerCipherSuites: c.PreferServerCipherSuites, 27 | SessionTicketsDisabled: c.SessionTicketsDisabled, 28 | SessionTicketKey: c.SessionTicketKey, 29 | ClientSessionCache: c.ClientSessionCache, 30 | MinVersion: c.MinVersion, 31 | MaxVersion: c.MaxVersion, 32 | CurvePreferences: c.CurvePreferences, 33 | DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, 34 | Renegotiation: c.Renegotiation, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. 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 | // +build go1.8 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "io" 12 | "net/http" 13 | ) 14 | 15 | func cloneTLSConfig(c *tls.Config) *tls.Config { 16 | c2 := c.Clone() 17 | c2.GetClientCertificate = c.GetClientCertificate // golang.org/issue/19264 18 | return c2 19 | } 20 | 21 | var _ http.Pusher = (*responseWriter)(nil) 22 | 23 | // Push implements http.Pusher. 24 | func (w *responseWriter) Push(target string, opts *http.PushOptions) error { 25 | internalOpts := pushOptions{} 26 | if opts != nil { 27 | internalOpts.Method = opts.Method 28 | internalOpts.Header = opts.Header 29 | } 30 | return w.push(target, internalOpts) 31 | } 32 | 33 | func configureServer18(h1 *http.Server, h2 *Server) error { 34 | if h2.IdleTimeout == 0 { 35 | if h1.IdleTimeout != 0 { 36 | h2.IdleTimeout = h1.IdleTimeout 37 | } else { 38 | h2.IdleTimeout = h1.ReadTimeout 39 | } 40 | } 41 | return nil 42 | } 43 | 44 | func shouldLogPanic(panicValue interface{}) bool { 45 | return panicValue != nil && panicValue != http.ErrAbortHandler 46 | } 47 | 48 | func reqGetBody(req *http.Request) func() (io.ReadCloser, error) { 49 | return req.GetBody 50 | } 51 | 52 | func reqBodyIsNoBody(body io.ReadCloser) bool { 53 | return body == http.NoBody 54 | } 55 | 56 | func go18httpNoBody() io.ReadCloser { return http.NoBody } // for tests only 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. 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 | // +build go1.9 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | ) 12 | 13 | func configureServer19(s *http.Server, conf *Server) error { 14 | s.RegisterOnShutdown(conf.state.startGracefulShutdown) 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/headermap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. 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 http2 6 | 7 | import ( 8 | "net/http" 9 | "strings" 10 | ) 11 | 12 | var ( 13 | commonLowerHeader = map[string]string{} // Go-Canonical-Case -> lower-case 14 | commonCanonHeader = map[string]string{} // lower-case -> Go-Canonical-Case 15 | ) 16 | 17 | func init() { 18 | for _, v := range []string{ 19 | "accept", 20 | "accept-charset", 21 | "accept-encoding", 22 | "accept-language", 23 | "accept-ranges", 24 | "age", 25 | "access-control-allow-origin", 26 | "allow", 27 | "authorization", 28 | "cache-control", 29 | "content-disposition", 30 | "content-encoding", 31 | "content-language", 32 | "content-length", 33 | "content-location", 34 | "content-range", 35 | "content-type", 36 | "cookie", 37 | "date", 38 | "etag", 39 | "expect", 40 | "expires", 41 | "from", 42 | "host", 43 | "if-match", 44 | "if-modified-since", 45 | "if-none-match", 46 | "if-unmodified-since", 47 | "last-modified", 48 | "link", 49 | "location", 50 | "max-forwards", 51 | "proxy-authenticate", 52 | "proxy-authorization", 53 | "range", 54 | "referer", 55 | "refresh", 56 | "retry-after", 57 | "server", 58 | "set-cookie", 59 | "strict-transport-security", 60 | "trailer", 61 | "transfer-encoding", 62 | "user-agent", 63 | "vary", 64 | "via", 65 | "www-authenticate", 66 | } { 67 | chk := http.CanonicalHeaderKey(v) 68 | commonLowerHeader[chk] = v 69 | commonCanonHeader[v] = chk 70 | } 71 | } 72 | 73 | func lowerHeader(v string) string { 74 | if s, ok := commonLowerHeader[v]; ok { 75 | return s 76 | } 77 | return strings.ToLower(v) 78 | } 79 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. 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 | // +build !go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | ) 13 | 14 | func configureTransport(t1 *http.Transport) (*Transport, error) { 15 | return nil, errTransportVersion 16 | } 17 | 18 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 19 | return 0 20 | 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. 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 | // +build !go1.8 6 | 7 | package http2 8 | 9 | import ( 10 | "io" 11 | "net/http" 12 | ) 13 | 14 | func configureServer18(h1 *http.Server, h2 *Server) error { 15 | // No IdleTimeout to sync prior to Go 1.8. 16 | return nil 17 | } 18 | 19 | func shouldLogPanic(panicValue interface{}) bool { 20 | return panicValue != nil 21 | } 22 | 23 | func reqGetBody(req *http.Request) func() (io.ReadCloser, error) { 24 | return nil 25 | } 26 | 27 | func reqBodyIsNoBody(io.ReadCloser) bool { return false } 28 | 29 | func go18httpNoBody() io.ReadCloser { return nil } // for tests only 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. 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 | // +build !go1.9 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | ) 12 | 13 | func configureServer19(s *http.Server, conf *Server) error { 14 | // not supported prior to go1.9 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/writesched_random.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. 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 http2 6 | 7 | import "math" 8 | 9 | // NewRandomWriteScheduler constructs a WriteScheduler that ignores HTTP/2 10 | // priorities. Control frames like SETTINGS and PING are written before DATA 11 | // frames, but if no control frames are queued and multiple streams have queued 12 | // HEADERS or DATA frames, Pop selects a ready stream arbitrarily. 13 | func NewRandomWriteScheduler() WriteScheduler { 14 | return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)} 15 | } 16 | 17 | type randomWriteScheduler struct { 18 | // zero are frames not associated with a specific stream. 19 | zero writeQueue 20 | 21 | // sq contains the stream-specific queues, keyed by stream ID. 22 | // When a stream is idle or closed, it's deleted from the map. 23 | sq map[uint32]*writeQueue 24 | 25 | // pool of empty queues for reuse. 26 | queuePool writeQueuePool 27 | } 28 | 29 | func (ws *randomWriteScheduler) OpenStream(streamID uint32, options OpenStreamOptions) { 30 | // no-op: idle streams are not tracked 31 | } 32 | 33 | func (ws *randomWriteScheduler) CloseStream(streamID uint32) { 34 | q, ok := ws.sq[streamID] 35 | if !ok { 36 | return 37 | } 38 | delete(ws.sq, streamID) 39 | ws.queuePool.put(q) 40 | } 41 | 42 | func (ws *randomWriteScheduler) AdjustStream(streamID uint32, priority PriorityParam) { 43 | // no-op: priorities are ignored 44 | } 45 | 46 | func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) { 47 | id := wr.StreamID() 48 | if id == 0 { 49 | ws.zero.push(wr) 50 | return 51 | } 52 | q, ok := ws.sq[id] 53 | if !ok { 54 | q = ws.queuePool.get() 55 | ws.sq[id] = q 56 | } 57 | q.push(wr) 58 | } 59 | 60 | func (ws *randomWriteScheduler) Pop() (FrameWriteRequest, bool) { 61 | // Control frames first. 62 | if !ws.zero.empty() { 63 | return ws.zero.shift(), true 64 | } 65 | // Iterate over all non-idle streams until finding one that can be consumed. 66 | for _, q := range ws.sq { 67 | if wr, ok := q.consume(math.MaxInt32); ok { 68 | return wr, true 69 | } 70 | } 71 | return FrameWriteRequest{}, false 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/trie.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package idna 8 | 9 | // appendMapping appends the mapping for the respective rune. isMapped must be 10 | // true. A mapping is a categorization of a rune as defined in UTS #46. 11 | func (c info) appendMapping(b []byte, s string) []byte { 12 | index := int(c >> indexShift) 13 | if c&xorBit == 0 { 14 | s := mappings[index:] 15 | return append(b, s[1:s[0]+1]...) 16 | } 17 | b = append(b, s...) 18 | if c&inlineXOR == inlineXOR { 19 | // TODO: support and handle two-byte inline masks 20 | b[len(b)-1] ^= byte(index) 21 | } else { 22 | for p := len(b) - int(xorData[index]); p < len(b); p++ { 23 | index++ 24 | b[p] ^= xorData[index] 25 | } 26 | } 27 | return b 28 | } 29 | 30 | // Sparse block handling code. 31 | 32 | type valueRange struct { 33 | value uint16 // header: value:stride 34 | lo, hi byte // header: lo:n 35 | } 36 | 37 | type sparseBlocks struct { 38 | values []valueRange 39 | offset []uint16 40 | } 41 | 42 | var idnaSparse = sparseBlocks{ 43 | values: idnaSparseValues[:], 44 | offset: idnaSparseOffset[:], 45 | } 46 | 47 | // Don't use newIdnaTrie to avoid unconditional linking in of the table. 48 | var trie = &idnaTrie{} 49 | 50 | // lookup determines the type of block n and looks up the value for b. 51 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 52 | // is a list of ranges with an accompanying value. Given a matching range r, 53 | // the value for b is by r.value + (b - r.lo) * stride. 54 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 55 | offset := t.offset[n] 56 | header := t.values[offset] 57 | lo := offset + 1 58 | hi := lo + uint16(header.lo) 59 | for lo < hi { 60 | m := lo + (hi-lo)/2 61 | r := t.values[m] 62 | if r.lo <= b && b <= r.hi { 63 | return r.value + uint16(b-r.lo)*header.value 64 | } 65 | if b < r.lo { 66 | hi = m 67 | } else { 68 | lo = m + 1 69 | } 70 | } 71 | return 0 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. 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 | // +build go1.10 6 | 7 | package bidirule 8 | 9 | func (t *Transformer) isFinal() bool { 10 | return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. 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 | // +build !go1.10 6 | 7 | package bidirule 8 | 9 | func (t *Transformer) isFinal() bool { 10 | if !t.isRTL() { 11 | return true 12 | } 13 | return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/gen_ranges.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. 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 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "unicode" 11 | 12 | "golang.org/x/text/internal/gen" 13 | "golang.org/x/text/internal/ucd" 14 | "golang.org/x/text/unicode/rangetable" 15 | ) 16 | 17 | // These tables are hand-extracted from: 18 | // http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedBidiClass.txt 19 | func visitDefaults(fn func(r rune, c Class)) { 20 | // first write default values for ranges listed above. 21 | visitRunes(fn, AL, []rune{ 22 | 0x0600, 0x07BF, // Arabic 23 | 0x08A0, 0x08FF, // Arabic Extended-A 24 | 0xFB50, 0xFDCF, // Arabic Presentation Forms 25 | 0xFDF0, 0xFDFF, 26 | 0xFE70, 0xFEFF, 27 | 0x0001EE00, 0x0001EEFF, // Arabic Mathematical Alpha Symbols 28 | }) 29 | visitRunes(fn, R, []rune{ 30 | 0x0590, 0x05FF, // Hebrew 31 | 0x07C0, 0x089F, // Nko et al. 32 | 0xFB1D, 0xFB4F, 33 | 0x00010800, 0x00010FFF, // Cypriot Syllabary et. al. 34 | 0x0001E800, 0x0001EDFF, 35 | 0x0001EF00, 0x0001EFFF, 36 | }) 37 | visitRunes(fn, ET, []rune{ // European Terminator 38 | 0x20A0, 0x20Cf, // Currency symbols 39 | }) 40 | rangetable.Visit(unicode.Noncharacter_Code_Point, func(r rune) { 41 | fn(r, BN) // Boundary Neutral 42 | }) 43 | ucd.Parse(gen.OpenUCDFile("DerivedCoreProperties.txt"), func(p *ucd.Parser) { 44 | if p.String(1) == "Default_Ignorable_Code_Point" { 45 | fn(p.Rune(0), BN) // Boundary Neutral 46 | } 47 | }) 48 | } 49 | 50 | func visitRunes(fn func(r rune, c Class), c Class, runes []rune) { 51 | for i := 0; i < len(runes); i += 2 { 52 | lo, hi := runes[i], runes[i+1] 53 | for j := lo; j <= hi; j++ { 54 | fn(j, c) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/gen_trieval.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. 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 | // +build ignore 6 | 7 | package main 8 | 9 | // Class is the Unicode BiDi class. Each rune has a single class. 10 | type Class uint 11 | 12 | const ( 13 | L Class = iota // LeftToRight 14 | R // RightToLeft 15 | EN // EuropeanNumber 16 | ES // EuropeanSeparator 17 | ET // EuropeanTerminator 18 | AN // ArabicNumber 19 | CS // CommonSeparator 20 | B // ParagraphSeparator 21 | S // SegmentSeparator 22 | WS // WhiteSpace 23 | ON // OtherNeutral 24 | BN // BoundaryNeutral 25 | NSM // NonspacingMark 26 | AL // ArabicLetter 27 | Control // Control LRO - PDI 28 | 29 | numClass 30 | 31 | LRO // LeftToRightOverride 32 | RLO // RightToLeftOverride 33 | LRE // LeftToRightEmbedding 34 | RLE // RightToLeftEmbedding 35 | PDF // PopDirectionalFormat 36 | LRI // LeftToRightIsolate 37 | RLI // RightToLeftIsolate 38 | FSI // FirstStrongIsolate 39 | PDI // PopDirectionalIsolate 40 | 41 | unknownClass = ^Class(0) 42 | ) 43 | 44 | var controlToClass = map[rune]Class{ 45 | 0x202D: LRO, // LeftToRightOverride, 46 | 0x202E: RLO, // RightToLeftOverride, 47 | 0x202A: LRE, // LeftToRightEmbedding, 48 | 0x202B: RLE, // RightToLeftEmbedding, 49 | 0x202C: PDF, // PopDirectionalFormat, 50 | 0x2066: LRI, // LeftToRightIsolate, 51 | 0x2067: RLI, // RightToLeftIsolate, 52 | 0x2068: FSI, // FirstStrongIsolate, 53 | 0x2069: PDI, // PopDirectionalIsolate, 54 | } 55 | 56 | // A trie entry has the following bits: 57 | // 7..5 XOR mask for brackets 58 | // 4 1: Bracket open, 0: Bracket close 59 | // 3..0 Class type 60 | 61 | const ( 62 | openMask = 0x10 63 | xorMaskShift = 5 64 | ) 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package bidi 4 | 5 | // Class is the Unicode BiDi class. Each rune has a single class. 6 | type Class uint 7 | 8 | const ( 9 | L Class = iota // LeftToRight 10 | R // RightToLeft 11 | EN // EuropeanNumber 12 | ES // EuropeanSeparator 13 | ET // EuropeanTerminator 14 | AN // ArabicNumber 15 | CS // CommonSeparator 16 | B // ParagraphSeparator 17 | S // SegmentSeparator 18 | WS // WhiteSpace 19 | ON // OtherNeutral 20 | BN // BoundaryNeutral 21 | NSM // NonspacingMark 22 | AL // ArabicLetter 23 | Control // Control LRO - PDI 24 | 25 | numClass 26 | 27 | LRO // LeftToRightOverride 28 | RLO // RightToLeftOverride 29 | LRE // LeftToRightEmbedding 30 | RLE // RightToLeftEmbedding 31 | PDF // PopDirectionalFormat 32 | LRI // LeftToRightIsolate 33 | RLI // RightToLeftIsolate 34 | FSI // FirstStrongIsolate 35 | PDI // PopDirectionalIsolate 36 | 37 | unknownClass = ^Class(0) 38 | ) 39 | 40 | var controlToClass = map[rune]Class{ 41 | 0x202D: LRO, // LeftToRightOverride, 42 | 0x202E: RLO, // RightToLeftOverride, 43 | 0x202A: LRE, // LeftToRightEmbedding, 44 | 0x202B: RLE, // RightToLeftEmbedding, 45 | 0x202C: PDF, // PopDirectionalFormat, 46 | 0x2066: LRI, // LeftToRightIsolate, 47 | 0x2067: RLI, // RightToLeftIsolate, 48 | 0x2068: FSI, // FirstStrongIsolate, 49 | 0x2069: PDI, // PopDirectionalIsolate, 50 | } 51 | 52 | // A trie entry has the following bits: 53 | // 7..5 XOR mask for brackets 54 | // 4 1: Bracket open, 0: Bracket close 55 | // 3..0 Class type 56 | 57 | const ( 58 | openMask = 0x10 59 | xorMaskShift = 5 60 | ) 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/trie.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. 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 norm 6 | 7 | type valueRange struct { 8 | value uint16 // header: value:stride 9 | lo, hi byte // header: lo:n 10 | } 11 | 12 | type sparseBlocks struct { 13 | values []valueRange 14 | offset []uint16 15 | } 16 | 17 | var nfcSparse = sparseBlocks{ 18 | values: nfcSparseValues[:], 19 | offset: nfcSparseOffset[:], 20 | } 21 | 22 | var nfkcSparse = sparseBlocks{ 23 | values: nfkcSparseValues[:], 24 | offset: nfkcSparseOffset[:], 25 | } 26 | 27 | var ( 28 | nfcData = newNfcTrie(0) 29 | nfkcData = newNfkcTrie(0) 30 | ) 31 | 32 | // lookupValue determines the type of block n and looks up the value for b. 33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 34 | // is a list of ranges with an accompanying value. Given a matching range r, 35 | // the value for b is by r.value + (b - r.lo) * stride. 36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 37 | offset := t.offset[n] 38 | header := t.values[offset] 39 | lo := offset + 1 40 | hi := lo + uint16(header.lo) 41 | for lo < hi { 42 | m := lo + (hi-lo)/2 43 | r := t.values[m] 44 | if r.lo <= b && b <= r.hi { 45 | return r.value + uint16(b-r.lo)*header.value 46 | } 47 | if b < r.lo { 48 | hi = m 49 | } else { 50 | lo = m + 1 51 | } 52 | } 53 | return 0 54 | } 55 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4 5 | - 1.5 6 | - 1.6 7 | - 1.7 8 | - 1.8 9 | - 1.9 10 | - tip 11 | 12 | go_import_path: gopkg.in/yaml.v2 13 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/LICENSE.libyaml: -------------------------------------------------------------------------------- 1 | The following files were ported to Go from C files of libyaml, and thus 2 | are still covered by their original copyright and license: 3 | 4 | apic.go 5 | emitterc.go 6 | parserc.go 7 | readerc.go 8 | scannerc.go 9 | writerc.go 10 | yamlh.go 11 | yamlprivateh.go 12 | 13 | Copyright (c) 2006 Kirill Simonov 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of 16 | this software and associated documentation files (the "Software"), to deal in 17 | the Software without restriction, including without limitation the rights to 18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 | of the Software, and to permit persons to whom the Software is furnished to do 20 | so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2011-2016 Canonical Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/go.mod: -------------------------------------------------------------------------------- 1 | module "gopkg.in/yaml.v2" 2 | 3 | require ( 4 | "gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405 5 | ) 6 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/writerc.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | // Set the writer error and return false. 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 5 | emitter.error = yaml_WRITER_ERROR 6 | emitter.problem = problem 7 | return false 8 | } 9 | 10 | // Flush the output buffer. 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 12 | if emitter.write_handler == nil { 13 | panic("write handler not set") 14 | } 15 | 16 | // Check if the buffer is empty. 17 | if emitter.buffer_pos == 0 { 18 | return true 19 | } 20 | 21 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 22 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 23 | } 24 | emitter.buffer_pos = 0 25 | return true 26 | } 27 | --------------------------------------------------------------------------------