├── .gitignore ├── CHANGELOG.md ├── MakeFile ├── README.md ├── example ├── Dockerfile ├── Makefile ├── app │ └── app.go ├── conf │ └── config.toml.sample ├── gsmeta └── main.go ├── game_service.go ├── src ├── config │ ├── config.go │ └── terminal_cmd.go ├── defines │ └── defines.go ├── log │ └── log.go ├── message │ ├── gs_adaptor.go │ ├── gs_handler.go │ ├── hotel_message.go │ ├── message_model.go │ ├── mvs_message.go │ └── push_message.go └── test │ ├── def_handler.go │ ├── hotel_message_test.go │ └── main_test.go └── vendor ├── commonlibs ├── errors │ └── errors.go ├── proto │ ├── common.pb.go │ ├── errorcode.pb.go │ ├── gsdirectory.pb.go │ ├── gshotel.pb.go │ ├── gsmvs.pb.go │ ├── simple.pb.go │ └── stream.pb.go └── servers │ ├── dir_register.go │ ├── room_manager.go │ ├── simple_client.go │ ├── stream_client.go │ └── stream_server.go ├── github.com ├── BurntSushi │ └── toml │ │ ├── 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 ├── davecgh │ └── go-spew │ │ ├── LICENSE │ │ └── spew │ │ ├── bypass.go │ │ ├── bypasssafe.go │ │ ├── common.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── dump.go │ │ ├── format.go │ │ └── spew.go ├── deckarep │ └── golang-set │ │ ├── LICENSE │ │ ├── README.md │ │ ├── iterator.go │ │ ├── set.go │ │ ├── threadsafe.go │ │ └── threadunsafe.go ├── golang │ └── protobuf │ │ ├── LICENSE │ │ ├── proto │ │ ├── clone.go │ │ ├── decode.go │ │ ├── deprecated.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 │ │ └── ptypes │ │ ├── any.go │ │ ├── any │ │ ├── any.pb.go │ │ └── any.proto │ │ ├── doc.go │ │ ├── duration.go │ │ ├── duration │ │ ├── duration.pb.go │ │ └── duration.proto │ │ ├── timestamp.go │ │ └── timestamp │ │ ├── timestamp.pb.go │ │ └── timestamp.proto └── op │ └── go-logging │ ├── CHANGELOG.md │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── README.md │ ├── backend.go │ ├── format.go │ ├── level.go │ ├── log_nix.go │ ├── log_windows.go │ ├── logger.go │ ├── memory.go │ ├── multi.go │ ├── syslog.go │ └── syslog_fallback.go ├── golang.org └── x │ ├── net │ ├── LICENSE │ ├── PATENTS │ ├── context │ │ ├── context.go │ │ ├── go17.go │ │ ├── go19.go │ │ ├── pre_go17.go │ │ └── pre_go19.go │ ├── http2 │ │ ├── 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 │ ├── internal │ │ └── timeseries │ │ │ └── timeseries.go │ ├── lex │ │ └── httplex │ │ │ └── httplex.go │ └── trace │ │ ├── events.go │ │ ├── histogram.go │ │ ├── trace.go │ │ ├── trace_go16.go │ │ └── trace_go17.go │ └── text │ ├── 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 ├── google.golang.org ├── genproto │ ├── LICENSE │ └── googleapis │ │ └── rpc │ │ └── status │ │ └── status.pb.go └── grpc │ ├── AUTHORS │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── backoff.go │ ├── balancer.go │ ├── balancer │ ├── balancer.go │ ├── base │ │ ├── balancer.go │ │ └── base.go │ └── roundrobin │ │ └── roundrobin.go │ ├── balancer_conn_wrappers.go │ ├── balancer_v1_wrapper.go │ ├── call.go │ ├── clientconn.go │ ├── codec.go │ ├── codegen.sh │ ├── codes │ ├── code_string.go │ └── codes.go │ ├── connectivity │ └── connectivity.go │ ├── credentials │ ├── credentials.go │ ├── credentials_util_go17.go │ ├── credentials_util_go18.go │ └── credentials_util_pre_go17.go │ ├── doc.go │ ├── encoding │ ├── encoding.go │ └── proto │ │ └── proto.go │ ├── go16.go │ ├── go17.go │ ├── grpclb.go │ ├── grpclb │ └── grpc_lb_v1 │ │ └── messages │ │ ├── messages.pb.go │ │ └── messages.proto │ ├── grpclb_picker.go │ ├── grpclb_remote_balancer.go │ ├── grpclb_util.go │ ├── grpclog │ ├── grpclog.go │ ├── logger.go │ └── loggerv2.go │ ├── interceptor.go │ ├── internal │ └── internal.go │ ├── keepalive │ └── keepalive.go │ ├── metadata │ └── metadata.go │ ├── naming │ ├── dns_resolver.go │ ├── go17.go │ ├── go18.go │ └── naming.go │ ├── peer │ └── peer.go │ ├── picker_wrapper.go │ ├── pickfirst.go │ ├── proxy.go │ ├── resolver │ ├── dns │ │ ├── dns_resolver.go │ │ ├── go17.go │ │ └── go18.go │ ├── passthrough │ │ └── passthrough.go │ └── resolver.go │ ├── resolver_conn_wrapper.go │ ├── rpc_util.go │ ├── server.go │ ├── service_config.go │ ├── stats │ ├── handlers.go │ └── stats.go │ ├── status │ └── status.go │ ├── stream.go │ ├── tap │ └── tap.go │ ├── trace.go │ ├── transport │ ├── bdp_estimator.go │ ├── control.go │ ├── go16.go │ ├── go17.go │ ├── handler_server.go │ ├── http2_client.go │ ├── http2_server.go │ ├── http_util.go │ ├── log.go │ └── transport.go │ └── vet.sh └── vendor.json /.gitignore: -------------------------------------------------------------------------------- 1 | debug 2 | .vscode 3 | *.exe 4 | *.toml 5 | res -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | #### version v1.0.1 4 | - 时间:2018-12-20 5 | ``` 6 | 1. OnRoomDetail 参数修改,添加组队信息 BrigadeList 7 | 2. 添加pushHandler主动接口 GetOffLineCacheData 断线重连获取断线期间的数据 8 | 3. SetFrameSyncRate 接口添加 cacheFrameMs 参数,并改为结构体 9 | 4. OnSetFrameSyncRate 接口添加 cacheFrameMs 参数 10 | 5. FrameDataList 改为 MsFrameDataList 11 | 6. 修复断线重连奔溃问题 12 | ``` 13 | 14 | #### version 0.0.1 15 | ``` 16 | 初次提交,只能本地调试 17 | ``` -------------------------------------------------------------------------------- /MakeFile: -------------------------------------------------------------------------------- 1 | .PHONY: all test1 test2 2 | 3 | all: test1 4 | 5 | 6 | test1: 7 | go test -v ./src/test 8 | 9 | test2: -------------------------------------------------------------------------------- /example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM registry.matchvs.com/language/alpine:1.0.0 2 | WORKDIR /gameServer-go 3 | COPY . /gameServer-go 4 | RUN ["chmod", "+x", "gameserver_go"] 5 | ENTRYPOINT ["./gameserver_go"] -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | DOCKER_BUILD=./docker_build 2 | BINARY = $(DOCKER_BUILD)/gameserver_go 3 | 4 | .PHONY: all test image clean 5 | all: build 6 | 7 | test: 8 | 9 | # CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BINARY) 不能修改 10 | build: 11 | rm -fr $(DOCKER_BUILD) 12 | mkdir -p $(DOCKER_BUILD) 13 | cp -r conf $(DOCKER_BUILD) 14 | cp Dockerfile $(DOCKER_BUILD) 15 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BINARY) 16 | 17 | # image 内容不能修改 18 | image: 19 | sudo docker build -t $(IMAGE) $(DOCKER_BUILD) 20 | sudo docker tag $(IMAGE) $(HARBOR)/$(IMAGE) 21 | sudo docker push $(HARBOR)/$(IMAGE) 22 | sudo docker rmi $(IMAGE) $(HARBOR)/$(IMAGE) -------------------------------------------------------------------------------- /example/conf/config.toml.sample: -------------------------------------------------------------------------------- 1 | [Server] 2 | Host = "0.0.0.0:36520" 3 | 4 | [Log] 5 | # Level's value can INFO、DEBUG、ERROR、WARNING, the default value is INFO 6 | Level = "DEBUG" 7 | 8 | # 独立部署参数配置 9 | [Register] 10 | Enable = false 11 | GameID = 123456 12 | SvcName = "svc-abc" 13 | PodName = "pod-abc" 14 | RemoteHost = "192.168.8.1" 15 | RemotePort = 9981 16 | LocalHost = "192.168.8.2" 17 | LocalPort = 30054 18 | 19 | # RoomManage 房间管理参数配置 20 | [RoomManage] 21 | # 需要使用房间管理 就设置为 true 22 | Enable = false 23 | SvcName = "svc-abc" 24 | PodName = "pod-abc" 25 | RemoteHost = "192.168.8.1" 26 | RemotePort = 9982 -------------------------------------------------------------------------------- /example/gsmeta: -------------------------------------------------------------------------------- 1 | { 2 | "ver": "1.0.0", 3 | "lang": "golang" 4 | } -------------------------------------------------------------------------------- /example/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * @Company: Matchvs 3 | * @Author: Ville 4 | * @Date: 2018-11-28 14:30:33 5 | * @LastEditors: Ville 6 | * @LastEditTime: 2018-12-18 17:11:33 7 | * @Description: matchvs game server example 8 | */ 9 | 10 | package main 11 | 12 | import ( 13 | "fmt" 14 | "os" 15 | "os/signal" 16 | "syscall" 17 | 18 | "github.com/matchvs/gameServer-go" 19 | "github.com/matchvs/gameServer-go/example/app" 20 | ) 21 | 22 | //程序函数入口 23 | func main() { 24 | // handler 实现接口 matchvs.BaseGsHandler 25 | handler := app.NewApp() 26 | // 创建 gameServer 27 | gsserver := matchvs.NewGameServer(handler, "") 28 | // 设置消息推送 29 | handler.SetPushHandler(gsserver.GetPushHandler()) 30 | // 启动 gameSever 服务 31 | go gsserver.Start() 32 | //检测系统信号 33 | sigCh := make(chan os.Signal, 1) 34 | signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) 35 | processStr := <-sigCh 36 | gsserver.Stop() 37 | fmt.Printf("service close %v", processStr) 38 | } 39 | -------------------------------------------------------------------------------- /src/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | 8 | "github.com/BurntSushi/toml" 9 | ) 10 | 11 | /** 12 | * GameServer 配置文件类型 13 | */ 14 | type GSConfig struct { 15 | Server *ServerConf `json:"server"` 16 | Log *LogConf `json:"log"` 17 | Register *RegisterConf `json:"register"` 18 | RoomManage *RoomConf `json:"room_manage"` 19 | } 20 | 21 | type ServerConf struct { 22 | Host string `json:"host"` 23 | } 24 | 25 | /** 26 | * 日志配置类型 27 | */ 28 | type LogConf struct { 29 | Level string `json:"level"` 30 | } 31 | 32 | type RegisterConf struct { 33 | Enable bool `json:"enable"` 34 | GameID uint32 `json:"game_id"` 35 | SvcName string `json:"svc_name"` 36 | PodName string `json:"pod_name"` 37 | RemoteHost string `json:"remote_host"` 38 | RemotePort int32 `json:"remote_port"` 39 | LocalHost string `json:"local_host"` 40 | LocalPort uint32 `json:"local_port"` 41 | } 42 | 43 | type RoomConf struct { 44 | Enable bool `json:"enable"` 45 | SvcName string `json:"svc_name"` 46 | PodName string `json:"pod_name"` 47 | RemoteHost string `json:"remote_host"` 48 | RemotePort int32 `json:"remote_port"` 49 | } 50 | 51 | //读取配置文件并创建 GSConfig 对象 52 | func NewGsConfig(fileName string) (gs *GSConfig, err error) { 53 | gs = new(GSConfig) 54 | if err = readConfig(fileName, gs); err != nil { 55 | fmt.Println("read configuration error: ", err) 56 | panic(err) 57 | } 58 | if gs.Server == nil { 59 | gs.Server = &ServerConf{ 60 | Host: "0.0.0.0:12345", 61 | } 62 | } 63 | return 64 | } 65 | 66 | //读取 toml 文件 67 | func readConfig(fileName string, v interface{}) (err error) { 68 | var ( 69 | file *os.File 70 | data []byte 71 | ) 72 | if file, err = os.Open(fileName); err != nil { 73 | return 74 | } 75 | 76 | if data, err = ioutil.ReadAll(file); err != nil { 77 | return 78 | } 79 | 80 | if err = toml.Unmarshal(data, v); err != nil { 81 | return 82 | } 83 | return 84 | } 85 | -------------------------------------------------------------------------------- /src/config/terminal_cmd.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "flag" 5 | "os" 6 | ) 7 | 8 | type TerminalCmd struct { 9 | ConfFile string 10 | ServerName string 11 | LogLevel string 12 | } 13 | 14 | //获取命令行参数 15 | func NewTerminalCmd() (cmd *TerminalCmd) { 16 | cmd = new(TerminalCmd) 17 | var help bool 18 | flag.BoolVar(&help, "h", false, "this help") 19 | flag.StringVar(&cmd.ConfFile, "c", "./conf/config.toml", "the configuration file name") 20 | flag.StringVar(&cmd.ServerName, "s", "GameServer", "the name for service") 21 | flag.Parse() 22 | if help { 23 | flag.Usage() 24 | os.Exit(0) 25 | } 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /src/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "io" 5 | "os" 6 | "path" 7 | 8 | logging "github.com/op/go-logging" 9 | ) 10 | 11 | /** 12 | *日志级别 13 | */ 14 | const ( 15 | critical int = iota 16 | err_or 17 | warning 18 | notice 19 | info 20 | debug 21 | ) 22 | 23 | var ( 24 | // 日志管理器 25 | mlog *logger 26 | /** 27 | * 日志输出格式 28 | */ 29 | logFormat = []string{ 30 | `%{shortfunc} ▶ %{level} %{message}`, 31 | `%{time:15:04:05.00} %{shortfile} ▶ %{level} %{id:03x} %{message}`, 32 | `%{color}%{time:15:04:05.00} %{shortfunc} %{shortfile} ▶ %{level} %{id:03x}%{color:reset} %{message}`, 33 | } 34 | 35 | /** 36 | * 日志级别与 string类型映射 37 | */ 38 | logLevelMap = map[string]int{ 39 | "CRITICAL": critical, 40 | "ERROR": err_or, 41 | "WARNING": warning, 42 | "NOTICE": notice, 43 | "INFO": info, 44 | "DEBUG": debug, 45 | } 46 | ) 47 | 48 | type logger struct { 49 | log *logging.Logger 50 | level string 51 | filePath string 52 | ModeName string 53 | format int 54 | } 55 | 56 | func init() { 57 | Init("DEBUG") 58 | } 59 | 60 | /** 61 | * 初始化日志 62 | * @param logLevel The arguments could be INFO, DEGUE, ERROR 63 | */ 64 | func Init(logLevel string) { 65 | mlog = newLog(logLevel) 66 | return 67 | } 68 | 69 | func newLog(level string) *logger { 70 | log := new(logger) 71 | log.level = level 72 | log.filePath = "./log" 73 | log.ModeName = "GameServer" 74 | log.format = 1 75 | log.log = logging.MustGetLogger(log.ModeName) 76 | log.AddLogBackend() 77 | return log 78 | } 79 | 80 | func (l *logger) AddLogBackend() { 81 | l.log.ExtraCalldepth = 2 82 | // backend1 := l.getFileBackend() 83 | backend2 := l.getStdOutBackend() 84 | logging.SetBackend(backend2) 85 | return 86 | } 87 | 88 | func SetLevel(level string) { 89 | logging.SetLevel(logging.Level(logLevelMap[level]), "") 90 | return 91 | } 92 | 93 | func (l *logger) getFileBackend() logging.LeveledBackend { 94 | //判断是否存在该文件夹 95 | if err := os.MkdirAll(l.filePath, 0777); err != nil { 96 | panic(err) 97 | } 98 | // 打开一个文件 99 | file, err := os.OpenFile(path.Join(l.filePath, l.ModeName+"_info.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) 100 | if err != nil { 101 | panic(err) 102 | } 103 | backend := l.getLogBackend(file, logLevelMap[l.level]) 104 | logging.SetBackend(backend) 105 | return backend 106 | } 107 | 108 | func (l *logger) getStdOutBackend() logging.LeveledBackend { 109 | bked := l.getLogBackend(os.Stderr, logLevelMap[l.level]) 110 | return bked 111 | } 112 | 113 | /** 114 | * 获取终端 115 | */ 116 | func (l *logger) getLogBackend(out io.Writer, level int) logging.LeveledBackend { 117 | backend := logging.NewLogBackend(out, "", 1) 118 | format := logging.MustStringFormatter(logFormat[l.format]) 119 | backendFormatter := logging.NewBackendFormatter(backend, format) 120 | backendLeveled := logging.AddModuleLevel(backendFormatter) 121 | backendLeveled.SetLevel(logging.Level(level), "") 122 | return backendLeveled 123 | } 124 | 125 | func (l *logger) logI(infmt string, args ...interface{}) { 126 | l.log.Infof(infmt, args...) 127 | return 128 | } 129 | func (l *logger) logE(infmt string, args ...interface{}) { 130 | l.log.Errorf(infmt, args...) 131 | return 132 | } 133 | func (l *logger) logW(infmt string, args ...interface{}) { 134 | l.log.Warningf(infmt, args...) 135 | return 136 | } 137 | func (l *logger) logD(infmt string, args ...interface{}) { 138 | l.log.Debugf(infmt, args...) 139 | return 140 | } 141 | 142 | func LogI(fmtstr string, args ...interface{}) { 143 | mlog.logI(fmtstr, args...) 144 | return 145 | } 146 | 147 | func LogW(fmtstr string, args ...interface{}) { 148 | mlog.logW(fmtstr, args...) 149 | return 150 | } 151 | 152 | func LogE(fmtstr string, args ...interface{}) { 153 | mlog.logE(fmtstr, args...) 154 | return 155 | } 156 | 157 | func LogD(fmtstr string, args ...interface{}) { 158 | mlog.logD(fmtstr, args...) 159 | return 160 | } 161 | -------------------------------------------------------------------------------- /src/message/gs_handler.go: -------------------------------------------------------------------------------- 1 | package message 2 | 3 | import ( 4 | "github.com/matchvs/gameServer-go/src/defines" 5 | ) 6 | 7 | type IHandler interface { 8 | // 创建房间回调 9 | OnCreateRoom(*defines.MsOnCreateRoom) error 10 | // 加入房间回调 11 | OnJoinRoom(*defines.MsOnJoinRoom) error 12 | // 关闭房间回调 13 | OnJoinOver(map[string]interface{}) error 14 | // 打开房间回调 15 | OnJoinOpen(map[string]interface{}) error 16 | // 离开房间回调 17 | OnLeaveRoom(map[string]interface{}) error 18 | // 踢人回调 19 | OnKickPlayer(map[string]interface{}) error 20 | // 连接状态回调 21 | OnUserState(map[string]interface{}) error 22 | // 获取房间信息回调 23 | OnRoomDetail(*defines.MsRoomDetail) error 24 | // 设置房间属性回调 25 | OnSetRoomProperty(map[string]interface{}) error 26 | // 房间连接回调 27 | OnHotelConnect(map[string]interface{}) error 28 | // 消息广播 29 | OnReceiveEvent(*defines.MsOnReciveEvent) error 30 | // 房间断开 31 | OnDeleteRoom(map[string]interface{}) error 32 | // 连接房间检测回调 33 | OnHotelCheckin(map[string]interface{}) error 34 | // 设置帧同步 35 | OnSetFrameSyncRate(*defines.MsFrameSyncRateNotify) error 36 | // 帧数据更新 37 | OnFrameUpdate(*defines.MsFrameDataList) error 38 | } 39 | -------------------------------------------------------------------------------- /src/message/message_model.go: -------------------------------------------------------------------------------- 1 | package message 2 | 3 | import ( 4 | pb "commonlibs/proto" 5 | "commonlibs/servers" 6 | "fmt" 7 | "sync" 8 | ) 9 | 10 | type MessageCache struct { 11 | JoinRoom map[string]*pb.Request 12 | lock sync.RWMutex 13 | } 14 | 15 | func NewMessageCache() *MessageCache { 16 | cache := new(MessageCache) 17 | cache.JoinRoom = make(map[string]*pb.Request) 18 | return cache 19 | } 20 | func (self *MessageCache) AddWaitJoin(roomID uint64, userID uint32, val *pb.Request) { 21 | self.lock.Lock() 22 | self.JoinRoom[fmt.Sprintf("%d_%d", roomID, userID)] = val 23 | self.lock.Unlock() 24 | } 25 | func (self *MessageCache) DelWaitJoin(roomID uint64, userID uint32) { 26 | self.lock.Lock() 27 | if len(self.JoinRoom) > 0 { 28 | delete(self.JoinRoom, fmt.Sprintf("%d_%d", roomID, userID)) 29 | } 30 | self.lock.Unlock() 31 | } 32 | func (self *MessageCache) GetWaitJoin(roomID uint64, userID uint32) (val *pb.Request) { 33 | self.lock.Lock() 34 | defer self.lock.Unlock() 35 | if len(self.JoinRoom) > 0 { 36 | val = self.JoinRoom[fmt.Sprintf("%d_%d", roomID, userID)] 37 | } 38 | return 39 | } 40 | 41 | type MessageModel struct { 42 | handle IHandler 43 | msgCache *MessageCache 44 | } 45 | 46 | func (m *MessageModel) CanDeal(cmdid int32) bool { 47 | return false 48 | } 49 | 50 | func (m *MessageModel) Route(connID uint64, req servers.GSRequest) (res []byte, err error) { 51 | res = []byte("hello") 52 | return 53 | } 54 | -------------------------------------------------------------------------------- /src/test/hotel_message_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | pb "commonlibs/proto" 5 | "encoding/json" 6 | "testing" 7 | "time" 8 | 9 | "github.com/golang/protobuf/proto" 10 | "github.com/matchvs/gameServer-go/src/message" 11 | ) 12 | 13 | func Test_FrameRateSet(t *testing.T) { 14 | var ( 15 | hd_test = &GsDefaultHandler{} 16 | cache_test = message.NewMessageCache() 17 | hotelMsg_test = message.NewHotelModel(hd_test, cache_test) 18 | ) 19 | rateSet := &pb.GSSetFrameSyncRate{ 20 | GameID: 200773, 21 | RoomID: 14567894561454, 22 | Priority: 0, 23 | FrameRate: 10, 24 | FrameIdx: 1, 25 | EnableGS: 1, 26 | } 27 | buf, _ := proto.Marshal(rateSet) 28 | req := getMessagePackage(uint32(pb.HotelGsCmdID_GSSetFrameSyncRateNotifyCMDID), buf) 29 | hotelMsg_test.Route(200773, req) 30 | Route_FrameNotify(hotelMsg_test) 31 | Route_FrameUpdate(hotelMsg_test) 32 | Route_RecvEvent(hotelMsg_test) 33 | time.Sleep(time.Second * 20) 34 | } 35 | 36 | func Route_FrameNotify(ht *message.HotelMessage) { 37 | 38 | // aw := new(sync.WaitGroup) 39 | go func() { 40 | for i := 0; i < 500; i++ { 41 | go func(index uint32) { 42 | frame := &pb.GSFrameDataNotify{ 43 | GameID: 200773, 44 | RoomID: 14567894561454, 45 | SrcUid: 123456, 46 | Priority: 0, 47 | CpProto: []byte("test gameServer"), 48 | TimeStamp: uint64(time.Now().Unix()), 49 | FrameIdx: index, 50 | } 51 | buf, _ := proto.Marshal(frame) 52 | req := getMessagePackage(1610, buf) 53 | 54 | ht.Route(200773, req) 55 | }(uint32(i)) 56 | time.Sleep(time.Millisecond * 50) 57 | } 58 | }() 59 | 60 | } 61 | 62 | func Route_FrameUpdate(ht *message.HotelMessage) { 63 | go func() { 64 | for i := 0; i < 500; i++ { 65 | go func(index uint32) { 66 | frame := &pb.GSFrameSyncNotify{ 67 | GameID: 200773, 68 | RoomID: 14567894561454, 69 | LastIdx: index, 70 | NextIdx: index + 1, 71 | Priority: 0, 72 | StartTS: uint64(time.Now().Unix()), 73 | EndTS: uint64(time.Now().Unix()), 74 | TimeStamp: uint64(time.Now().Unix()), 75 | } 76 | buf, _ := proto.Marshal(frame) 77 | req := getMessagePackage(uint32(pb.HotelGsCmdID_GSFrameSyncNotifyCMDID), buf) 78 | ht.Route(200773, req) 79 | }(uint32(i)) 80 | time.Sleep(time.Millisecond * 100) 81 | } 82 | }() 83 | 84 | } 85 | 86 | func Route_RecvEvent(ht *message.HotelMessage) { 87 | go func() { 88 | for i := 0; i < 5000; i++ { 89 | go func(index uint32) { 90 | data := &struct { 91 | Cmd string `json:"cmd"` 92 | Data string `json:"data"` 93 | }{Cmd: "event", Data: "gameServer test uint"} 94 | // fmt.Printf("data:%v", *data) 95 | databuf, _ := json.Marshal(data) 96 | for j := 0; j <= 20; j++ { 97 | if j >= 20 { 98 | data.Cmd = "end" 99 | databuf, _ = json.Marshal(data) 100 | } 101 | event := &pb.HotelBroadcast{ 102 | GameID: 200773, 103 | RoomID: 14567894561454, 104 | Flag: 1, 105 | DstUids: []uint32{123456}, 106 | CpProto: databuf, 107 | } 108 | buf, _ := proto.Marshal(event) 109 | req := getMessagePackage(uint32(pb.HotelGsCmdID_HotelBroadcastCMDID), buf) 110 | ht.Route(200773, req) 111 | time.Sleep(time.Millisecond * 100) 112 | } 113 | return 114 | }(uint32(i)) 115 | time.Sleep(time.Millisecond * 100) 116 | } 117 | }() 118 | } 119 | 120 | // get a test package which simulate server data package 121 | func getMessagePackage(cmdID uint32, msg []byte) *pb.Package_Frame { 122 | pkg := new(pb.Package_Frame) 123 | pkg.CmdId = cmdID 124 | pkg.Version = 2 125 | pkg.Reserved = 234 126 | pkg.Type = pb.Package_LeagueMessage 127 | pkg.Message = msg[:] 128 | return pkg 129 | } 130 | -------------------------------------------------------------------------------- /src/test/main_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "time" 7 | 8 | matchvs "github.com/matchvs/gameServer-go" 9 | "github.com/matchvs/gameServer-go/example/app" 10 | ) 11 | 12 | func Test_MainServer(t *testing.T) { 13 | // 定义业务处理对象这个业务类需要 继承接口 14 | handler := &app.App{} 15 | // 创建 gameServer 16 | gsserver := matchvs.NewGameServer(handler, "../../example/conf/config.toml.sample") 17 | handler.SetPushHandler(gsserver.GetPushHandler()) 18 | 19 | go func() { 20 | // 启动 gameSever 服务 21 | gsserver.Start() 22 | }() 23 | 24 | for { 25 | select { 26 | case <-time.After(time.Second * 10): 27 | fmt.Println("结束服务") 28 | gsserver.Stop() 29 | time.Sleep(time.Second * 2) 30 | return 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vendor/commonlibs/errors/errors.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | import ( 4 | "runtime" 5 | 6 | "github.com/davecgh/go-spew/spew" 7 | "github.com/matchvs/gameServer-go/src/log" 8 | ) 9 | 10 | // 产生panic时的调用栈打印 11 | func PrintPanicStack(extras ...interface{}) { 12 | if x := recover(); x != nil { 13 | log.LogE("recover:%v", x) 14 | i := 0 15 | funcName, file, line, ok := runtime.Caller(i) 16 | for ok { 17 | log.LogE("frame %v:[func:%v,file:%v,line:%v]", i, runtime.FuncForPC(funcName).Name(), file, line) 18 | i++ 19 | funcName, file, line, ok = runtime.Caller(i) 20 | } 21 | 22 | for k := range extras { 23 | log.LogE("EXRAS#%v DATA:%v", k, spew.Sdump(extras[k])) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/commonlibs/servers/dir_register.go: -------------------------------------------------------------------------------- 1 | package servers 2 | 3 | import ( 4 | pb "commonlibs/proto" 5 | "fmt" 6 | "hash/crc32" 7 | "time" 8 | 9 | "github.com/golang/protobuf/proto" 10 | "github.com/matchvs/gameServer-go/src/config" 11 | "github.com/matchvs/gameServer-go/src/log" 12 | ) 13 | 14 | var pushHandler *RegisterPushHandler 15 | 16 | type RegisterPushHandler struct { 17 | } 18 | 19 | func (self *RegisterPushHandler) RecvPush(req *pb.Package_Frame) error { 20 | data, _ := proto.Marshal(req) 21 | log.LogD("收到消息:[CmdID=%d][UserID=%d][length=%v]", req.CmdId, req.UserId, len(data)) 22 | return nil 23 | } 24 | 25 | type DirRegister struct { 26 | stream *StreamClient 27 | regConf *config.RegisterConf 28 | stop bool 29 | load uint32 30 | } 31 | 32 | func NewRegister(conf *config.RegisterConf) (reg *DirRegister) { 33 | addr := fmt.Sprintf("%s:%d", conf.RemoteHost, conf.RemotePort) 34 | reg = new(DirRegister) 35 | pushHandler = new(RegisterPushHandler) 36 | reg.stream = NewStreamClient(addr, crc32.ChecksumIEEE([]byte(conf.SvcName+conf.PodName)), pushHandler) 37 | reg.stop = false 38 | reg.load = 0 39 | reg.regConf = conf 40 | return 41 | } 42 | 43 | func (r *DirRegister) Run() { 44 | 45 | if r.regConf.Enable == false { 46 | log.LogI("register is disable") 47 | return 48 | } 49 | 50 | if err := r.stream.Start(); err != nil { 51 | log.LogE("register fail remote addr : %s:%d", r.regConf.RemoteHost, r.regConf.RemotePort) 52 | return 53 | } 54 | log.LogI("register success : %s:%d", r.regConf.RemoteHost, r.regConf.RemotePort) 55 | r.Login() 56 | go func() { 57 | for { 58 | if r.stop { 59 | r.Loginout() 60 | r.stream.Stop() 61 | break 62 | } 63 | if r.stream.ConnectSuccess() == false { 64 | log.LogW("disconnect server : %s:%d", r.regConf.RemoteHost, r.regConf.RemotePort) 65 | break 66 | } 67 | r.heartBeat() 68 | time.Sleep(time.Second * time.Duration(5)) 69 | } 70 | }() 71 | } 72 | func (r *DirRegister) Stop() { 73 | r.stop = true 74 | } 75 | 76 | func (r *DirRegister) Login() { 77 | pkg := &pb.GSLogin{} 78 | pkg.GameID = r.regConf.GameID 79 | pkg.SvcName = r.regConf.SvcName 80 | pkg.PodName = r.regConf.PodName 81 | pkg.Host = r.regConf.LocalHost 82 | pkg.Port = r.regConf.LocalPort 83 | msg, _ := proto.Marshal(pkg) 84 | r.stream.Push(uint32(pb.GSDirectoryCmdID_GSLoginCmd), msg) 85 | } 86 | 87 | func (r *DirRegister) Loginout() { 88 | pkg := &pb.GSLogout{} 89 | pkg.GameID = r.regConf.GameID 90 | pkg.SvcName = r.regConf.SvcName 91 | pkg.PodName = r.regConf.PodName 92 | msg, _ := proto.Marshal(pkg) 93 | r.stream.Push(uint32(pb.GSDirectoryCmdID_GSLogoutCmd), msg) 94 | } 95 | 96 | func (r *DirRegister) heartBeat() { 97 | hb := &pb.GSHeartbeat{ 98 | Load: r.load, 99 | } 100 | message, _ := proto.Marshal(hb) 101 | r.stream.Push(uint32(pb.GSDirectoryCmdID_GSHeartbeatCmd), message) 102 | } 103 | -------------------------------------------------------------------------------- /vendor/commonlibs/servers/simple_client.go: -------------------------------------------------------------------------------- 1 | package servers 2 | 3 | import ( 4 | pb "commonlibs/proto" 5 | "fmt" 6 | 7 | "github.com/matchvs/gameServer-go/src/log" 8 | "golang.org/x/net/context" 9 | "google.golang.org/grpc" 10 | ) 11 | 12 | // SimpleClient grpc客户端 13 | type SimpleClient struct { 14 | serverAddr string 15 | conn *grpc.ClientConn 16 | client pb.SimpleServiceClient 17 | } 18 | 19 | // NewSimpleClient 构造函数 20 | func NewSimpleClient(addr string) (client *SimpleClient) { 21 | client = &SimpleClient{} 22 | client.serverAddr = addr 23 | // connect 24 | // gen new client 25 | 26 | return 27 | } 28 | 29 | func (c *SimpleClient) Run() (err error) { 30 | var opts []grpc.DialOption 31 | opts = append(opts, grpc.WithInsecure()) 32 | 33 | conn, err := grpc.Dial(c.serverAddr, opts...) 34 | if err != nil { 35 | log.LogE("grpc.Dial failed:", err) 36 | return 37 | } 38 | c.conn = conn 39 | c.client = pb.NewSimpleServiceClient(conn) 40 | return 41 | } 42 | 43 | // Close 断开连接 44 | func (c *SimpleClient) Close() { 45 | c.conn.Close() 46 | } 47 | 48 | // Send 发送消息 49 | func (c *SimpleClient) Send(req *pb.Package_Frame) (rep *pb.Package_Frame, err error) { 50 | rep, err = c.client.SimpleRequest(context.Background(), req) 51 | if err != nil { 52 | fmt.Println("SimpleRequest failed") 53 | } 54 | return 55 | } 56 | -------------------------------------------------------------------------------- /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/decode_meta.go: -------------------------------------------------------------------------------- 1 | package toml 2 | 3 | import "strings" 4 | 5 | // MetaData allows access to meta information about TOML data that may not 6 | // be inferrable via reflection. In particular, whether a key has been defined 7 | // and the TOML type of a key. 8 | type MetaData struct { 9 | mapping map[string]interface{} 10 | types map[string]tomlType 11 | keys []Key 12 | decoded map[string]bool 13 | context Key // Used only during decoding. 14 | } 15 | 16 | // IsDefined returns true if the key given exists in the TOML data. The key 17 | // should be specified hierarchially. e.g., 18 | // 19 | // // access the TOML key 'a.b.c' 20 | // IsDefined("a", "b", "c") 21 | // 22 | // IsDefined will return false if an empty key given. Keys are case sensitive. 23 | func (md *MetaData) IsDefined(key ...string) bool { 24 | if len(key) == 0 { 25 | return false 26 | } 27 | 28 | var hash map[string]interface{} 29 | var ok bool 30 | var hashOrVal interface{} = md.mapping 31 | for _, k := range key { 32 | if hash, ok = hashOrVal.(map[string]interface{}); !ok { 33 | return false 34 | } 35 | if hashOrVal, ok = hash[k]; !ok { 36 | return false 37 | } 38 | } 39 | return true 40 | } 41 | 42 | // Type returns a string representation of the type of the key specified. 43 | // 44 | // Type will return the empty string if given an empty key or a key that 45 | // does not exist. Keys are case sensitive. 46 | func (md *MetaData) Type(key ...string) string { 47 | fullkey := strings.Join(key, ".") 48 | if typ, ok := md.types[fullkey]; ok { 49 | return typ.typeString() 50 | } 51 | return "" 52 | } 53 | 54 | // Key is the type of any TOML key, including key groups. Use (MetaData).Keys 55 | // to get values of this type. 56 | type Key []string 57 | 58 | func (k Key) String() string { 59 | return strings.Join(k, ".") 60 | } 61 | 62 | func (k Key) maybeQuotedAll() string { 63 | var ss []string 64 | for i := range k { 65 | ss = append(ss, k.maybeQuoted(i)) 66 | } 67 | return strings.Join(ss, ".") 68 | } 69 | 70 | func (k Key) maybeQuoted(i int) string { 71 | quote := false 72 | for _, c := range k[i] { 73 | if !isBareKeyChar(c) { 74 | quote = true 75 | break 76 | } 77 | } 78 | if quote { 79 | return "\"" + strings.Replace(k[i], "\"", "\\\"", -1) + "\"" 80 | } 81 | return k[i] 82 | } 83 | 84 | func (k Key) add(piece string) Key { 85 | newKey := make(Key, len(k)+1) 86 | copy(newKey, k) 87 | newKey[len(k)] = piece 88 | return newKey 89 | } 90 | 91 | // Keys returns a slice of every key in the TOML data, including key groups. 92 | // Each key is itself a slice, where the first element is the top of the 93 | // hierarchy and the last is the most specific. 94 | // 95 | // The list will have the same order as the keys appeared in the TOML data. 96 | // 97 | // All keys returned are non-empty. 98 | func (md *MetaData) Keys() []Key { 99 | return md.keys 100 | } 101 | 102 | // Undecoded returns all keys that have not been decoded in the order in which 103 | // they appear in the original TOML document. 104 | // 105 | // This includes keys that haven't been decoded because of a Primitive value. 106 | // Once the Primitive value is decoded, the keys will be considered decoded. 107 | // 108 | // Also note that decoding into an empty interface will result in no decoding, 109 | // and so no keys will be considered decoded. 110 | // 111 | // In this sense, the Undecoded keys correspond to keys in the TOML document 112 | // that do not have a concrete type in your representation. 113 | func (md *MetaData) Undecoded() []Key { 114 | undecoded := make([]Key, 0, len(md.keys)) 115 | for _, key := range md.keys { 116 | if !md.decoded[key.String()] { 117 | undecoded = append(undecoded, key) 118 | } 119 | } 120 | return undecoded 121 | } 122 | -------------------------------------------------------------------------------- /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/BurntSushi/toml/type_check.go: -------------------------------------------------------------------------------- 1 | package toml 2 | 3 | // tomlType represents any Go type that corresponds to a TOML type. 4 | // While the first draft of the TOML spec has a simplistic type system that 5 | // probably doesn't need this level of sophistication, we seem to be militating 6 | // toward adding real composite types. 7 | type tomlType interface { 8 | typeString() string 9 | } 10 | 11 | // typeEqual accepts any two types and returns true if they are equal. 12 | func typeEqual(t1, t2 tomlType) bool { 13 | if t1 == nil || t2 == nil { 14 | return false 15 | } 16 | return t1.typeString() == t2.typeString() 17 | } 18 | 19 | func typeIsHash(t tomlType) bool { 20 | return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash) 21 | } 22 | 23 | type tomlBaseType string 24 | 25 | func (btype tomlBaseType) typeString() string { 26 | return string(btype) 27 | } 28 | 29 | func (btype tomlBaseType) String() string { 30 | return btype.typeString() 31 | } 32 | 33 | var ( 34 | tomlInteger tomlBaseType = "Integer" 35 | tomlFloat tomlBaseType = "Float" 36 | tomlDatetime tomlBaseType = "Datetime" 37 | tomlString tomlBaseType = "String" 38 | tomlBool tomlBaseType = "Bool" 39 | tomlArray tomlBaseType = "Array" 40 | tomlHash tomlBaseType = "Hash" 41 | tomlArrayHash tomlBaseType = "ArrayHash" 42 | ) 43 | 44 | // typeOfPrimitive returns a tomlType of any primitive value in TOML. 45 | // Primitive values are: Integer, Float, Datetime, String and Bool. 46 | // 47 | // Passing a lexer item other than the following will cause a BUG message 48 | // to occur: itemString, itemBool, itemInteger, itemFloat, itemDatetime. 49 | func (p *parser) typeOfPrimitive(lexItem item) tomlType { 50 | switch lexItem.typ { 51 | case itemInteger: 52 | return tomlInteger 53 | case itemFloat: 54 | return tomlFloat 55 | case itemDatetime: 56 | return tomlDatetime 57 | case itemString: 58 | return tomlString 59 | case itemMultilineString: 60 | return tomlString 61 | case itemRawString: 62 | return tomlString 63 | case itemRawMultilineString: 64 | return tomlString 65 | case itemBool: 66 | return tomlBool 67 | } 68 | p.bug("Cannot infer primitive type of lex item '%s'.", lexItem) 69 | panic("unreachable") 70 | } 71 | 72 | // typeOfArray returns a tomlType for an array given a list of types of its 73 | // values. 74 | // 75 | // In the current spec, if an array is homogeneous, then its type is always 76 | // "Array". If the array is not homogeneous, an error is generated. 77 | func (p *parser) typeOfArray(types []tomlType) tomlType { 78 | // Empty arrays are cool. 79 | if len(types) == 0 { 80 | return tomlArray 81 | } 82 | 83 | theType := types[0] 84 | for _, t := range types[1:] { 85 | if !typeEqual(theType, t) { 86 | p.panicf("Array contains values of type '%s' and '%s', but "+ 87 | "arrays must be homogeneous.", theType, t) 88 | } 89 | } 90 | return tomlArray 91 | } 92 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe !go1.4 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/deckarep/golang-set/LICENSE: -------------------------------------------------------------------------------- 1 | Open Source Initiative OSI - The MIT License (MIT):Licensing 2 | 3 | The MIT License (MIT) 4 | Copyright (c) 2013 Ralph Caraveo (deckarep@gmail.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is furnished to do 11 | so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/deckarep/golang-set/iterator.go: -------------------------------------------------------------------------------- 1 | /* 2 | Open Source Initiative OSI - The MIT License (MIT):Licensing 3 | 4 | The MIT License (MIT) 5 | Copyright (c) 2013 Ralph Caraveo (deckarep@gmail.com) 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 11 | of the Software, and to permit persons to whom the Software is furnished to do 12 | so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | */ 25 | 26 | package mapset 27 | 28 | // Iterator defines an iterator over a Set, its C channel can be used to range over the Set's 29 | // elements. 30 | type Iterator struct { 31 | C <-chan interface{} 32 | stop chan struct{} 33 | } 34 | 35 | // Stop stops the Iterator, no further elements will be received on C, C will be closed. 36 | func (i *Iterator) Stop() { 37 | // Allows for Stop() to be called multiple times 38 | // (close() panics when called on already closed channel) 39 | defer func() { 40 | recover() 41 | }() 42 | 43 | close(i.stop) 44 | 45 | // Exhaust any remaining elements. 46 | for range i.C { 47 | } 48 | } 49 | 50 | // newIterator returns a new Iterator instance together with its item and stop channels. 51 | func newIterator() (*Iterator, chan<- interface{}, <-chan struct{}) { 52 | itemChan := make(chan interface{}) 53 | stopChan := make(chan struct{}) 54 | return &Iterator{ 55 | C: itemChan, 56 | stop: stopChan, 57 | }, itemChan, stopChan 58 | } 59 | -------------------------------------------------------------------------------- /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/golang/protobuf/proto/deprecated.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2018 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 | package proto 33 | 34 | import "errors" 35 | 36 | // Deprecated: do not use. 37 | type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 } 38 | 39 | // Deprecated: do not use. 40 | func GetStats() Stats { return Stats{} } 41 | 42 | // Deprecated: do not use. 43 | func MarshalMessageSet(interface{}) ([]byte, error) { 44 | return nil, errors.New("proto: not implemented") 45 | } 46 | 47 | // Deprecated: do not use. 48 | func UnmarshalMessageSet([]byte, interface{}) error { 49 | return errors.New("proto: not implemented") 50 | } 51 | 52 | // Deprecated: do not use. 53 | func MarshalMessageSetJSON(interface{}) ([]byte, error) { 54 | return nil, errors.New("proto: not implemented") 55 | } 56 | 57 | // Deprecated: do not use. 58 | func UnmarshalMessageSetJSON([]byte, interface{}) error { 59 | return errors.New("proto: not implemented") 60 | } 61 | 62 | // Deprecated: do not use. 63 | func RegisterMessageSetType(Message, int32, string) {} 64 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/doc.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2016 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 | /* 33 | Package ptypes contains code for interacting with well-known types. 34 | */ 35 | package ptypes 36 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 2.0.0-rc1 (2016-02-11) 4 | 5 | Time flies and it has been three years since this package was first released. 6 | There have been a couple of API changes I have wanted to do for some time but 7 | I've tried to maintain backwards compatibility. Some inconsistencies in the 8 | API have started to show, proper vendor support in Go out of the box and 9 | the fact that `go vet` will give warnings -- I have decided to bump the major 10 | version. 11 | 12 | * Make eg. `Info` and `Infof` do different things. You want to change all calls 13 | to `Info` with a string format go to `Infof` etc. In many cases, `go vet` will 14 | guide you. 15 | * `Id` in `Record` is now called `ID` 16 | 17 | ## 1.0.0 (2013-02-21) 18 | 19 | Initial release 20 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Alec Thomas 2 | Guilhem Lettron 3 | Ivan Daniluk 4 | Nimi Wariboko Jr 5 | Róbert Selvek 6 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Örjan Persson. 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/github.com/op/go-logging/README.md: -------------------------------------------------------------------------------- 1 | ## Golang logging library 2 | 3 | [![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/op/go-logging) [![build](https://img.shields.io/travis/op/go-logging.svg?style=flat)](https://travis-ci.org/op/go-logging) 4 | 5 | Package logging implements a logging infrastructure for Go. Its output format 6 | is customizable and supports different logging backends like syslog, file and 7 | memory. Multiple backends can be utilized with different log levels per backend 8 | and logger. 9 | 10 | **_NOTE:_** backwards compatibility promise have been dropped for master. Please 11 | vendor this package or use `gopkg.in/op/go-logging.v1` for previous version. See 12 | [changelog](CHANGELOG.md) for details. 13 | 14 | ## Example 15 | 16 | Let's have a look at an [example](examples/example.go) which demonstrates most 17 | of the features found in this library. 18 | 19 | [![Example Output](examples/example.png)](examples/example.go) 20 | 21 | ```go 22 | package main 23 | 24 | import ( 25 | "os" 26 | 27 | "github.com/op/go-logging" 28 | ) 29 | 30 | var log = logging.MustGetLogger("example") 31 | 32 | // Example format string. Everything except the message has a custom color 33 | // which is dependent on the log level. Many fields have a custom output 34 | // formatting too, eg. the time returns the hour down to the milli second. 35 | var format = logging.MustStringFormatter( 36 | `%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`, 37 | ) 38 | 39 | // Password is just an example type implementing the Redactor interface. Any 40 | // time this is logged, the Redacted() function will be called. 41 | type Password string 42 | 43 | func (p Password) Redacted() interface{} { 44 | return logging.Redact(string(p)) 45 | } 46 | 47 | func main() { 48 | // For demo purposes, create two backend for os.Stderr. 49 | backend1 := logging.NewLogBackend(os.Stderr, "", 0) 50 | backend2 := logging.NewLogBackend(os.Stderr, "", 0) 51 | 52 | // For messages written to backend2 we want to add some additional 53 | // information to the output, including the used log level and the name of 54 | // the function. 55 | backend2Formatter := logging.NewBackendFormatter(backend2, format) 56 | 57 | // Only errors and more severe messages should be sent to backend1 58 | backend1Leveled := logging.AddModuleLevel(backend1) 59 | backend1Leveled.SetLevel(logging.ERROR, "") 60 | 61 | // Set the backends to be used. 62 | logging.SetBackend(backend1Leveled, backend2Formatter) 63 | 64 | log.Debugf("debug %s", Password("secret")) 65 | log.Info("info") 66 | log.Notice("notice") 67 | log.Warning("warning") 68 | log.Error("err") 69 | log.Critical("crit") 70 | } 71 | ``` 72 | 73 | ## Installing 74 | 75 | ### Using *go get* 76 | 77 | $ go get github.com/op/go-logging 78 | 79 | After this command *go-logging* is ready to use. Its source will be in: 80 | 81 | $GOPATH/src/pkg/github.com/op/go-logging 82 | 83 | You can use `go get -u` to update the package. 84 | 85 | ## Documentation 86 | 87 | For docs, see http://godoc.org/github.com/op/go-logging or run: 88 | 89 | $ godoc github.com/op/go-logging 90 | 91 | ## Additional resources 92 | 93 | * [wslog](https://godoc.org/github.com/cryptix/exp/wslog) -- exposes log messages through a WebSocket. 94 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/backend.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Örjan Persson. 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 logging 6 | 7 | // defaultBackend is the backend used for all logging calls. 8 | var defaultBackend LeveledBackend 9 | 10 | // Backend is the interface which a log backend need to implement to be able to 11 | // be used as a logging backend. 12 | type Backend interface { 13 | Log(Level, int, *Record) error 14 | } 15 | 16 | // SetBackend replaces the backend currently set with the given new logging 17 | // backend. 18 | func SetBackend(backends ...Backend) LeveledBackend { 19 | var backend Backend 20 | if len(backends) == 1 { 21 | backend = backends[0] 22 | } else { 23 | backend = MultiLogger(backends...) 24 | } 25 | 26 | defaultBackend = AddModuleLevel(backend) 27 | return defaultBackend 28 | } 29 | 30 | // SetLevel sets the logging level for the specified module. The module 31 | // corresponds to the string specified in GetLogger. 32 | func SetLevel(level Level, module string) { 33 | defaultBackend.SetLevel(level, module) 34 | } 35 | 36 | // GetLevel returns the logging level for the specified module. 37 | func GetLevel(module string) Level { 38 | return defaultBackend.GetLevel(module) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/level.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Örjan Persson. 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 logging 6 | 7 | import ( 8 | "errors" 9 | "strings" 10 | "sync" 11 | ) 12 | 13 | // ErrInvalidLogLevel is used when an invalid log level has been used. 14 | var ErrInvalidLogLevel = errors.New("logger: invalid log level") 15 | 16 | // Level defines all available log levels for log messages. 17 | type Level int 18 | 19 | // Log levels. 20 | const ( 21 | CRITICAL Level = iota 22 | ERROR 23 | WARNING 24 | NOTICE 25 | INFO 26 | DEBUG 27 | ) 28 | 29 | var levelNames = []string{ 30 | "CRITICAL", 31 | "ERROR", 32 | "WARNING", 33 | "NOTICE", 34 | "INFO", 35 | "DEBUG", 36 | } 37 | 38 | // String returns the string representation of a logging level. 39 | func (p Level) String() string { 40 | return levelNames[p] 41 | } 42 | 43 | // LogLevel returns the log level from a string representation. 44 | func LogLevel(level string) (Level, error) { 45 | for i, name := range levelNames { 46 | if strings.EqualFold(name, level) { 47 | return Level(i), nil 48 | } 49 | } 50 | return ERROR, ErrInvalidLogLevel 51 | } 52 | 53 | // Leveled interface is the interface required to be able to add leveled 54 | // logging. 55 | type Leveled interface { 56 | GetLevel(string) Level 57 | SetLevel(Level, string) 58 | IsEnabledFor(Level, string) bool 59 | } 60 | 61 | // LeveledBackend is a log backend with additional knobs for setting levels on 62 | // individual modules to different levels. 63 | type LeveledBackend interface { 64 | Backend 65 | Leveled 66 | } 67 | 68 | type moduleLeveled struct { 69 | levels map[string]Level 70 | backend Backend 71 | formatter Formatter 72 | once sync.Once 73 | } 74 | 75 | // AddModuleLevel wraps a log backend with knobs to have different log levels 76 | // for different modules. 77 | func AddModuleLevel(backend Backend) LeveledBackend { 78 | var leveled LeveledBackend 79 | var ok bool 80 | if leveled, ok = backend.(LeveledBackend); !ok { 81 | leveled = &moduleLeveled{ 82 | levels: make(map[string]Level), 83 | backend: backend, 84 | } 85 | } 86 | return leveled 87 | } 88 | 89 | // GetLevel returns the log level for the given module. 90 | func (l *moduleLeveled) GetLevel(module string) Level { 91 | level, exists := l.levels[module] 92 | if exists == false { 93 | level, exists = l.levels[""] 94 | // no configuration exists, default to debug 95 | if exists == false { 96 | level = DEBUG 97 | } 98 | } 99 | return level 100 | } 101 | 102 | // SetLevel sets the log level for the given module. 103 | func (l *moduleLeveled) SetLevel(level Level, module string) { 104 | l.levels[module] = level 105 | } 106 | 107 | // IsEnabledFor will return true if logging is enabled for the given module. 108 | func (l *moduleLeveled) IsEnabledFor(level Level, module string) bool { 109 | return level <= l.GetLevel(module) 110 | } 111 | 112 | func (l *moduleLeveled) Log(level Level, calldepth int, rec *Record) (err error) { 113 | if l.IsEnabledFor(level, rec.Module) { 114 | // TODO get rid of traces of formatter here. BackendFormatter should be used. 115 | rec.formatter = l.getFormatterAndCacheCurrent() 116 | err = l.backend.Log(level, calldepth+1, rec) 117 | } 118 | return 119 | } 120 | 121 | func (l *moduleLeveled) getFormatterAndCacheCurrent() Formatter { 122 | l.once.Do(func() { 123 | if l.formatter == nil { 124 | l.formatter = getFormatter() 125 | } 126 | }) 127 | return l.formatter 128 | } 129 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/log_nix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | // Copyright 2013, Örjan Persson. 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 logging 8 | 9 | import ( 10 | "bytes" 11 | "fmt" 12 | "io" 13 | "log" 14 | ) 15 | 16 | type color int 17 | 18 | const ( 19 | ColorBlack = iota + 30 20 | ColorRed 21 | ColorGreen 22 | ColorYellow 23 | ColorBlue 24 | ColorMagenta 25 | ColorCyan 26 | ColorWhite 27 | ) 28 | 29 | var ( 30 | colors = []string{ 31 | CRITICAL: ColorSeq(ColorMagenta), 32 | ERROR: ColorSeq(ColorRed), 33 | WARNING: ColorSeq(ColorYellow), 34 | NOTICE: ColorSeq(ColorGreen), 35 | DEBUG: ColorSeq(ColorCyan), 36 | } 37 | boldcolors = []string{ 38 | CRITICAL: ColorSeqBold(ColorMagenta), 39 | ERROR: ColorSeqBold(ColorRed), 40 | WARNING: ColorSeqBold(ColorYellow), 41 | NOTICE: ColorSeqBold(ColorGreen), 42 | DEBUG: ColorSeqBold(ColorCyan), 43 | } 44 | ) 45 | 46 | // LogBackend utilizes the standard log module. 47 | type LogBackend struct { 48 | Logger *log.Logger 49 | Color bool 50 | ColorConfig []string 51 | } 52 | 53 | // NewLogBackend creates a new LogBackend. 54 | func NewLogBackend(out io.Writer, prefix string, flag int) *LogBackend { 55 | return &LogBackend{Logger: log.New(out, prefix, flag)} 56 | } 57 | 58 | // Log implements the Backend interface. 59 | func (b *LogBackend) Log(level Level, calldepth int, rec *Record) error { 60 | if b.Color { 61 | col := colors[level] 62 | if len(b.ColorConfig) > int(level) && b.ColorConfig[level] != "" { 63 | col = b.ColorConfig[level] 64 | } 65 | 66 | buf := &bytes.Buffer{} 67 | buf.Write([]byte(col)) 68 | buf.Write([]byte(rec.Formatted(calldepth + 1))) 69 | buf.Write([]byte("\033[0m")) 70 | // For some reason, the Go logger arbitrarily decided "2" was the correct 71 | // call depth... 72 | return b.Logger.Output(calldepth+2, buf.String()) 73 | } 74 | 75 | return b.Logger.Output(calldepth+2, rec.Formatted(calldepth+1)) 76 | } 77 | 78 | // ConvertColors takes a list of ints representing colors for log levels and 79 | // converts them into strings for ANSI color formatting 80 | func ConvertColors(colors []int, bold bool) []string { 81 | converted := []string{} 82 | for _, i := range colors { 83 | if bold { 84 | converted = append(converted, ColorSeqBold(color(i))) 85 | } else { 86 | converted = append(converted, ColorSeq(color(i))) 87 | } 88 | } 89 | 90 | return converted 91 | } 92 | 93 | func ColorSeq(color color) string { 94 | return fmt.Sprintf("\033[%dm", int(color)) 95 | } 96 | 97 | func ColorSeqBold(color color) string { 98 | return fmt.Sprintf("\033[%d;1m", int(color)) 99 | } 100 | 101 | func doFmtVerbLevelColor(layout string, level Level, output io.Writer) { 102 | if layout == "bold" { 103 | output.Write([]byte(boldcolors[level])) 104 | } else if layout == "reset" { 105 | output.Write([]byte("\033[0m")) 106 | } else { 107 | output.Write([]byte(colors[level])) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/log_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // Copyright 2013, Örjan Persson. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package logging 7 | 8 | import ( 9 | "bytes" 10 | "io" 11 | "log" 12 | "syscall" 13 | ) 14 | 15 | var ( 16 | kernel32DLL = syscall.NewLazyDLL("kernel32.dll") 17 | setConsoleTextAttributeProc = kernel32DLL.NewProc("SetConsoleTextAttribute") 18 | ) 19 | 20 | // Character attributes 21 | // Note: 22 | // -- The attributes are combined to produce various colors (e.g., Blue + Green will create Cyan). 23 | // Clearing all foreground or background colors results in black; setting all creates white. 24 | // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes. 25 | const ( 26 | fgBlack = 0x0000 27 | fgBlue = 0x0001 28 | fgGreen = 0x0002 29 | fgCyan = 0x0003 30 | fgRed = 0x0004 31 | fgMagenta = 0x0005 32 | fgYellow = 0x0006 33 | fgWhite = 0x0007 34 | fgIntensity = 0x0008 35 | fgMask = 0x000F 36 | ) 37 | 38 | var ( 39 | colors = []uint16{ 40 | INFO: fgWhite, 41 | CRITICAL: fgMagenta, 42 | ERROR: fgRed, 43 | WARNING: fgYellow, 44 | NOTICE: fgGreen, 45 | DEBUG: fgCyan, 46 | } 47 | boldcolors = []uint16{ 48 | INFO: fgWhite | fgIntensity, 49 | CRITICAL: fgMagenta | fgIntensity, 50 | ERROR: fgRed | fgIntensity, 51 | WARNING: fgYellow | fgIntensity, 52 | NOTICE: fgGreen | fgIntensity, 53 | DEBUG: fgCyan | fgIntensity, 54 | } 55 | ) 56 | 57 | type file interface { 58 | Fd() uintptr 59 | } 60 | 61 | // LogBackend utilizes the standard log module. 62 | type LogBackend struct { 63 | Logger *log.Logger 64 | Color bool 65 | 66 | // f is set to a non-nil value if the underlying writer which logs writes to 67 | // implements the file interface. This makes us able to colorise the output. 68 | f file 69 | } 70 | 71 | // NewLogBackend creates a new LogBackend. 72 | func NewLogBackend(out io.Writer, prefix string, flag int) *LogBackend { 73 | b := &LogBackend{Logger: log.New(out, prefix, flag)} 74 | 75 | // Unfortunately, the API used only takes an io.Writer where the Windows API 76 | // need the actual fd to change colors. 77 | if f, ok := out.(file); ok { 78 | b.f = f 79 | } 80 | 81 | return b 82 | } 83 | 84 | func (b *LogBackend) Log(level Level, calldepth int, rec *Record) error { 85 | if b.Color && b.f != nil { 86 | buf := &bytes.Buffer{} 87 | setConsoleTextAttribute(b.f, colors[level]) 88 | buf.Write([]byte(rec.Formatted(calldepth + 1))) 89 | err := b.Logger.Output(calldepth+2, buf.String()) 90 | setConsoleTextAttribute(b.f, fgWhite) 91 | return err 92 | } 93 | return b.Logger.Output(calldepth+2, rec.Formatted(calldepth+1)) 94 | } 95 | 96 | // setConsoleTextAttribute sets the attributes of characters written to the 97 | // console screen buffer by the WriteFile or WriteConsole function. 98 | // See http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx. 99 | func setConsoleTextAttribute(f file, attribute uint16) bool { 100 | ok, _, _ := setConsoleTextAttributeProc.Call(f.Fd(), uintptr(attribute), 0) 101 | return ok != 0 102 | } 103 | 104 | func doFmtVerbLevelColor(layout string, level Level, output io.Writer) { 105 | // TODO not supported on Windows since the io.Writer here is actually a 106 | // bytes.Buffer. 107 | } 108 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/multi.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Örjan Persson. 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 logging 6 | 7 | // TODO remove Level stuff from the multi logger. Do one thing. 8 | 9 | // multiLogger is a log multiplexer which can be used to utilize multiple log 10 | // backends at once. 11 | type multiLogger struct { 12 | backends []LeveledBackend 13 | } 14 | 15 | // MultiLogger creates a logger which contain multiple loggers. 16 | func MultiLogger(backends ...Backend) LeveledBackend { 17 | var leveledBackends []LeveledBackend 18 | for _, backend := range backends { 19 | leveledBackends = append(leveledBackends, AddModuleLevel(backend)) 20 | } 21 | return &multiLogger{leveledBackends} 22 | } 23 | 24 | // Log passes the log record to all backends. 25 | func (b *multiLogger) Log(level Level, calldepth int, rec *Record) (err error) { 26 | for _, backend := range b.backends { 27 | if backend.IsEnabledFor(level, rec.Module) { 28 | // Shallow copy of the record for the formatted cache on Record and get the 29 | // record formatter from the backend. 30 | r2 := *rec 31 | if e := backend.Log(level, calldepth+1, &r2); e != nil { 32 | err = e 33 | } 34 | } 35 | } 36 | return 37 | } 38 | 39 | // GetLevel returns the highest level enabled by all backends. 40 | func (b *multiLogger) GetLevel(module string) Level { 41 | var level Level 42 | for _, backend := range b.backends { 43 | if backendLevel := backend.GetLevel(module); backendLevel > level { 44 | level = backendLevel 45 | } 46 | } 47 | return level 48 | } 49 | 50 | // SetLevel propagates the same level to all backends. 51 | func (b *multiLogger) SetLevel(level Level, module string) { 52 | for _, backend := range b.backends { 53 | backend.SetLevel(level, module) 54 | } 55 | } 56 | 57 | // IsEnabledFor returns true if any of the backends are enabled for it. 58 | func (b *multiLogger) IsEnabledFor(level Level, module string) bool { 59 | for _, backend := range b.backends { 60 | if backend.IsEnabledFor(level, module) { 61 | return true 62 | } 63 | } 64 | return false 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/syslog.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Örjan Persson. 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 !windows,!plan9 6 | 7 | package logging 8 | 9 | import "log/syslog" 10 | 11 | // SyslogBackend is a simple logger to syslog backend. It automatically maps 12 | // the internal log levels to appropriate syslog log levels. 13 | type SyslogBackend struct { 14 | Writer *syslog.Writer 15 | } 16 | 17 | // NewSyslogBackend connects to the syslog daemon using UNIX sockets with the 18 | // given prefix. If prefix is not given, the prefix will be derived from the 19 | // launched command. 20 | func NewSyslogBackend(prefix string) (b *SyslogBackend, err error) { 21 | var w *syslog.Writer 22 | w, err = syslog.New(syslog.LOG_CRIT, prefix) 23 | return &SyslogBackend{w}, err 24 | } 25 | 26 | // NewSyslogBackendPriority is the same as NewSyslogBackend, but with custom 27 | // syslog priority, like syslog.LOG_LOCAL3|syslog.LOG_DEBUG etc. 28 | func NewSyslogBackendPriority(prefix string, priority syslog.Priority) (b *SyslogBackend, err error) { 29 | var w *syslog.Writer 30 | w, err = syslog.New(priority, prefix) 31 | return &SyslogBackend{w}, err 32 | } 33 | 34 | // Log implements the Backend interface. 35 | func (b *SyslogBackend) Log(level Level, calldepth int, rec *Record) error { 36 | line := rec.Formatted(calldepth + 1) 37 | switch level { 38 | case CRITICAL: 39 | return b.Writer.Crit(line) 40 | case ERROR: 41 | return b.Writer.Err(line) 42 | case WARNING: 43 | return b.Writer.Warning(line) 44 | case NOTICE: 45 | return b.Writer.Notice(line) 46 | case INFO: 47 | return b.Writer.Info(line) 48 | case DEBUG: 49 | return b.Writer.Debug(line) 50 | default: 51 | } 52 | panic("unhandled log level") 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/op/go-logging/syslog_fallback.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Örjan Persson. 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 windows plan9 6 | 7 | package logging 8 | 9 | import ( 10 | "fmt" 11 | ) 12 | 13 | type Priority int 14 | 15 | type SyslogBackend struct { 16 | } 17 | 18 | func NewSyslogBackend(prefix string) (b *SyslogBackend, err error) { 19 | return nil, fmt.Errorf("Platform does not support syslog") 20 | } 21 | 22 | func NewSyslogBackendPriority(prefix string, priority Priority) (b *SyslogBackend, err error) { 23 | return nil, fmt.Errorf("Platform does not support syslog") 24 | } 25 | 26 | func (b *SyslogBackend) Log(level Level, calldepth int, rec *Record) error { 27 | return fmt.Errorf("Platform does not support syslog") 28 | } 29 | -------------------------------------------------------------------------------- /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/context/context.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 context defines the Context type, which carries deadlines, 6 | // cancelation signals, and other request-scoped values across API boundaries 7 | // and between processes. 8 | // As of Go 1.7 this package is available in the standard library under the 9 | // name context. https://golang.org/pkg/context. 10 | // 11 | // Incoming requests to a server should create a Context, and outgoing calls to 12 | // servers should accept a Context. The chain of function calls between must 13 | // propagate the Context, optionally replacing it with a modified copy created 14 | // using WithDeadline, WithTimeout, WithCancel, or WithValue. 15 | // 16 | // Programs that use Contexts should follow these rules to keep interfaces 17 | // consistent across packages and enable static analysis tools to check context 18 | // propagation: 19 | // 20 | // Do not store Contexts inside a struct type; instead, pass a Context 21 | // explicitly to each function that needs it. The Context should be the first 22 | // parameter, typically named ctx: 23 | // 24 | // func DoSomething(ctx context.Context, arg Arg) error { 25 | // // ... use ctx ... 26 | // } 27 | // 28 | // Do not pass a nil Context, even if a function permits it. Pass context.TODO 29 | // if you are unsure about which Context to use. 30 | // 31 | // Use context Values only for request-scoped data that transits processes and 32 | // APIs, not for passing optional parameters to functions. 33 | // 34 | // The same Context may be passed to functions running in different goroutines; 35 | // Contexts are safe for simultaneous use by multiple goroutines. 36 | // 37 | // See http://blog.golang.org/context for example code for a server that uses 38 | // Contexts. 39 | package context // import "golang.org/x/net/context" 40 | 41 | // Background returns a non-nil, empty Context. It is never canceled, has no 42 | // values, and has no deadline. It is typically used by the main function, 43 | // initialization, and tests, and as the top-level Context for incoming 44 | // requests. 45 | func Background() Context { 46 | return background 47 | } 48 | 49 | // TODO returns a non-nil, empty Context. Code should use context.TODO when 50 | // it's unclear which Context to use or it is not yet available (because the 51 | // surrounding function has not yet been extended to accept a Context 52 | // parameter). TODO is recognized by static analysis tools that determine 53 | // whether Contexts are propagated correctly in a program. 54 | func TODO() Context { 55 | return todo 56 | } 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go17.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 6 | 7 | package context 8 | 9 | import ( 10 | "context" // standard library's context, as of Go 1.7 11 | "time" 12 | ) 13 | 14 | var ( 15 | todo = context.TODO() 16 | background = context.Background() 17 | ) 18 | 19 | // Canceled is the error returned by Context.Err when the context is canceled. 20 | var Canceled = context.Canceled 21 | 22 | // DeadlineExceeded is the error returned by Context.Err when the context's 23 | // deadline passes. 24 | var DeadlineExceeded = context.DeadlineExceeded 25 | 26 | // WithCancel returns a copy of parent with a new Done channel. The returned 27 | // context's Done channel is closed when the returned cancel function is called 28 | // or when the parent context's Done channel is closed, whichever happens first. 29 | // 30 | // Canceling this context releases resources associated with it, so code should 31 | // call cancel as soon as the operations running in this Context complete. 32 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { 33 | ctx, f := context.WithCancel(parent) 34 | return ctx, CancelFunc(f) 35 | } 36 | 37 | // WithDeadline returns a copy of the parent context with the deadline adjusted 38 | // to be no later than d. If the parent's deadline is already earlier than d, 39 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned 40 | // context's Done channel is closed when the deadline expires, when the returned 41 | // cancel function is called, or when the parent context's Done channel is 42 | // closed, whichever happens first. 43 | // 44 | // Canceling this context releases resources associated with it, so code should 45 | // call cancel as soon as the operations running in this Context complete. 46 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { 47 | ctx, f := context.WithDeadline(parent, deadline) 48 | return ctx, CancelFunc(f) 49 | } 50 | 51 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). 52 | // 53 | // Canceling this context releases resources associated with it, so code should 54 | // call cancel as soon as the operations running in this Context complete: 55 | // 56 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) { 57 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) 58 | // defer cancel() // releases resources if slowOperation completes before timeout elapses 59 | // return slowOperation(ctx) 60 | // } 61 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { 62 | return WithDeadline(parent, time.Now().Add(timeout)) 63 | } 64 | 65 | // WithValue returns a copy of parent in which the value associated with key is 66 | // val. 67 | // 68 | // Use context Values only for request-scoped data that transits processes and 69 | // APIs, not for passing optional parameters to functions. 70 | func WithValue(parent Context, key interface{}, val interface{}) Context { 71 | return context.WithValue(parent, key, val) 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 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 context 8 | 9 | import "context" // standard library's context, as of Go 1.7 10 | 11 | // A Context carries a deadline, a cancelation signal, and other values across 12 | // API boundaries. 13 | // 14 | // Context's methods may be called by multiple goroutines simultaneously. 15 | type Context = context.Context 16 | 17 | // A CancelFunc tells an operation to abandon its work. 18 | // A CancelFunc does not wait for the work to stop. 19 | // After the first call, subsequent calls to a CancelFunc do nothing. 20 | type CancelFunc = context.CancelFunc 21 | -------------------------------------------------------------------------------- /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/configure_transport.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 | "crypto/tls" 11 | "fmt" 12 | "net/http" 13 | ) 14 | 15 | func configureTransport(t1 *http.Transport) (*Transport, error) { 16 | connPool := new(clientConnPool) 17 | t2 := &Transport{ 18 | ConnPool: noDialClientConnPool{connPool}, 19 | t1: t1, 20 | } 21 | connPool.t = t2 22 | if err := registerHTTPSProtocol(t1, noDialH2RoundTripper{t2}); err != nil { 23 | return nil, err 24 | } 25 | if t1.TLSClientConfig == nil { 26 | t1.TLSClientConfig = new(tls.Config) 27 | } 28 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "h2") { 29 | t1.TLSClientConfig.NextProtos = append([]string{"h2"}, t1.TLSClientConfig.NextProtos...) 30 | } 31 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "http/1.1") { 32 | t1.TLSClientConfig.NextProtos = append(t1.TLSClientConfig.NextProtos, "http/1.1") 33 | } 34 | upgradeFn := func(authority string, c *tls.Conn) http.RoundTripper { 35 | addr := authorityAddr("https", authority) 36 | if used, err := connPool.addConnIfNeeded(addr, t2, c); err != nil { 37 | go c.Close() 38 | return erringRoundTripper{err} 39 | } else if !used { 40 | // Turns out we don't need this c. 41 | // For example, two goroutines made requests to the same host 42 | // at the same time, both kicking off TCP dials. (since protocol 43 | // was unknown) 44 | go c.Close() 45 | } 46 | return t2 47 | } 48 | if m := t1.TLSNextProto; len(m) == 0 { 49 | t1.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{ 50 | "h2": upgradeFn, 51 | } 52 | } else { 53 | m["h2"] = upgradeFn 54 | } 55 | return t2, nil 56 | } 57 | 58 | // registerHTTPSProtocol calls Transport.RegisterProtocol but 59 | // converting panics into errors. 60 | func registerHTTPSProtocol(t *http.Transport, rt http.RoundTripper) (err error) { 61 | defer func() { 62 | if e := recover(); e != nil { 63 | err = fmt.Errorf("%v", e) 64 | } 65 | }() 66 | t.RegisterProtocol("https", rt) 67 | return nil 68 | } 69 | 70 | // noDialH2RoundTripper is a RoundTripper which only tries to complete the request 71 | // if there's already has a cached connection to the host. 72 | type noDialH2RoundTripper struct{ t *Transport } 73 | 74 | func (rt noDialH2RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { 75 | res, err := rt.t.RoundTrip(req) 76 | if isNoCachedConnError(err) { 77 | return nil, http.ErrSkipAltProtocol 78 | } 79 | return res, err 80 | } 81 | -------------------------------------------------------------------------------- /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 | remain := (1<<31 - 1) - f.n 45 | if n > remain { 46 | return false 47 | } 48 | f.n += n 49 | return true 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.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 6 | 7 | package http2 8 | 9 | import ( 10 | "context" 11 | "net" 12 | "net/http" 13 | "net/http/httptrace" 14 | "time" 15 | ) 16 | 17 | type contextContext interface { 18 | context.Context 19 | } 20 | 21 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 22 | ctx, cancel = context.WithCancel(context.Background()) 23 | ctx = context.WithValue(ctx, http.LocalAddrContextKey, c.LocalAddr()) 24 | if hs := opts.baseConfig(); hs != nil { 25 | ctx = context.WithValue(ctx, http.ServerContextKey, hs) 26 | } 27 | return 28 | } 29 | 30 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 31 | return context.WithCancel(ctx) 32 | } 33 | 34 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 35 | return req.WithContext(ctx) 36 | } 37 | 38 | type clientTrace httptrace.ClientTrace 39 | 40 | func reqContext(r *http.Request) context.Context { return r.Context() } 41 | 42 | func (t *Transport) idleConnTimeout() time.Duration { 43 | if t.t1 != nil { 44 | return t.t1.IdleConnTimeout 45 | } 46 | return 0 47 | } 48 | 49 | func setResponseUncompressed(res *http.Response) { res.Uncompressed = true } 50 | 51 | func traceGotConn(req *http.Request, cc *ClientConn) { 52 | trace := httptrace.ContextClientTrace(req.Context()) 53 | if trace == nil || trace.GotConn == nil { 54 | return 55 | } 56 | ci := httptrace.GotConnInfo{Conn: cc.tconn} 57 | cc.mu.Lock() 58 | ci.Reused = cc.nextStreamID > 1 59 | ci.WasIdle = len(cc.streams) == 0 && ci.Reused 60 | if ci.WasIdle && !cc.lastActive.IsZero() { 61 | ci.IdleTime = time.Now().Sub(cc.lastActive) 62 | } 63 | cc.mu.Unlock() 64 | 65 | trace.GotConn(ci) 66 | } 67 | 68 | func traceWroteHeaders(trace *clientTrace) { 69 | if trace != nil && trace.WroteHeaders != nil { 70 | trace.WroteHeaders() 71 | } 72 | } 73 | 74 | func traceGot100Continue(trace *clientTrace) { 75 | if trace != nil && trace.Got100Continue != nil { 76 | trace.Got100Continue() 77 | } 78 | } 79 | 80 | func traceWait100Continue(trace *clientTrace) { 81 | if trace != nil && trace.Wait100Continue != nil { 82 | trace.Wait100Continue() 83 | } 84 | } 85 | 86 | func traceWroteRequest(trace *clientTrace, err error) { 87 | if trace != nil && trace.WroteRequest != nil { 88 | trace.WroteRequest(httptrace.WroteRequestInfo{Err: err}) 89 | } 90 | } 91 | 92 | func traceFirstResponseByte(trace *clientTrace) { 93 | if trace != nil && trace.GotFirstResponseByte != nil { 94 | trace.GotFirstResponseByte() 95 | } 96 | } 97 | 98 | func requestTrace(req *http.Request) *clientTrace { 99 | trace := httptrace.ContextClientTrace(req.Context()) 100 | return (*clientTrace)(trace) 101 | } 102 | 103 | // Ping sends a PING frame to the server and waits for the ack. 104 | func (cc *ClientConn) Ping(ctx context.Context) error { 105 | return cc.ping(ctx) 106 | } 107 | -------------------------------------------------------------------------------- /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/gotrack.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 | // Defensive debug-only utility to track that functions run on the 6 | // goroutine that they're supposed to. 7 | 8 | package http2 9 | 10 | import ( 11 | "bytes" 12 | "errors" 13 | "fmt" 14 | "os" 15 | "runtime" 16 | "strconv" 17 | "sync" 18 | ) 19 | 20 | var DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1" 21 | 22 | type goroutineLock uint64 23 | 24 | func newGoroutineLock() goroutineLock { 25 | if !DebugGoroutines { 26 | return 0 27 | } 28 | return goroutineLock(curGoroutineID()) 29 | } 30 | 31 | func (g goroutineLock) check() { 32 | if !DebugGoroutines { 33 | return 34 | } 35 | if curGoroutineID() != uint64(g) { 36 | panic("running on the wrong goroutine") 37 | } 38 | } 39 | 40 | func (g goroutineLock) checkNotOn() { 41 | if !DebugGoroutines { 42 | return 43 | } 44 | if curGoroutineID() == uint64(g) { 45 | panic("running on the wrong goroutine") 46 | } 47 | } 48 | 49 | var goroutineSpace = []byte("goroutine ") 50 | 51 | func curGoroutineID() uint64 { 52 | bp := littleBuf.Get().(*[]byte) 53 | defer littleBuf.Put(bp) 54 | b := *bp 55 | b = b[:runtime.Stack(b, false)] 56 | // Parse the 4707 out of "goroutine 4707 [" 57 | b = bytes.TrimPrefix(b, goroutineSpace) 58 | i := bytes.IndexByte(b, ' ') 59 | if i < 0 { 60 | panic(fmt.Sprintf("No space found in %q", b)) 61 | } 62 | b = b[:i] 63 | n, err := parseUintBytes(b, 10, 64) 64 | if err != nil { 65 | panic(fmt.Sprintf("Failed to parse goroutine ID out of %q: %v", b, err)) 66 | } 67 | return n 68 | } 69 | 70 | var littleBuf = sync.Pool{ 71 | New: func() interface{} { 72 | buf := make([]byte, 64) 73 | return &buf 74 | }, 75 | } 76 | 77 | // parseUintBytes is like strconv.ParseUint, but using a []byte. 78 | func parseUintBytes(s []byte, base int, bitSize int) (n uint64, err error) { 79 | var cutoff, maxVal uint64 80 | 81 | if bitSize == 0 { 82 | bitSize = int(strconv.IntSize) 83 | } 84 | 85 | s0 := s 86 | switch { 87 | case len(s) < 1: 88 | err = strconv.ErrSyntax 89 | goto Error 90 | 91 | case 2 <= base && base <= 36: 92 | // valid base; nothing to do 93 | 94 | case base == 0: 95 | // Look for octal, hex prefix. 96 | switch { 97 | case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'): 98 | base = 16 99 | s = s[2:] 100 | if len(s) < 1 { 101 | err = strconv.ErrSyntax 102 | goto Error 103 | } 104 | case s[0] == '0': 105 | base = 8 106 | default: 107 | base = 10 108 | } 109 | 110 | default: 111 | err = errors.New("invalid base " + strconv.Itoa(base)) 112 | goto Error 113 | } 114 | 115 | n = 0 116 | cutoff = cutoff64(base) 117 | maxVal = 1<= base { 135 | n = 0 136 | err = strconv.ErrSyntax 137 | goto Error 138 | } 139 | 140 | if n >= cutoff { 141 | // n*base overflows 142 | n = 1<<64 - 1 143 | err = strconv.ErrRange 144 | goto Error 145 | } 146 | n *= uint64(base) 147 | 148 | n1 := n + uint64(v) 149 | if n1 < n || n1 > maxVal { 150 | // n+v overflows 151 | n = 1<<64 - 1 152 | err = strconv.ErrRange 153 | goto Error 154 | } 155 | n = n1 156 | } 157 | 158 | return n, nil 159 | 160 | Error: 161 | return n, &strconv.NumError{Func: "ParseUint", Num: string(s0), Err: err} 162 | } 163 | 164 | // Return the first number n such that n*base >= 1<<64. 165 | func cutoff64(base int) uint64 { 166 | if base < 2 { 167 | return 0 168 | } 169 | return (1<<64-1)/uint64(base) + 1 170 | } 171 | -------------------------------------------------------------------------------- /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_go17.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 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "net" 12 | "net/http" 13 | "time" 14 | ) 15 | 16 | type contextContext interface { 17 | Done() <-chan struct{} 18 | Err() error 19 | } 20 | 21 | type fakeContext struct{} 22 | 23 | func (fakeContext) Done() <-chan struct{} { return nil } 24 | func (fakeContext) Err() error { panic("should not be called") } 25 | 26 | func reqContext(r *http.Request) fakeContext { 27 | return fakeContext{} 28 | } 29 | 30 | func setResponseUncompressed(res *http.Response) { 31 | // Nothing. 32 | } 33 | 34 | type clientTrace struct{} 35 | 36 | func requestTrace(*http.Request) *clientTrace { return nil } 37 | func traceGotConn(*http.Request, *ClientConn) {} 38 | func traceFirstResponseByte(*clientTrace) {} 39 | func traceWroteHeaders(*clientTrace) {} 40 | func traceWroteRequest(*clientTrace, error) {} 41 | func traceGot100Continue(trace *clientTrace) {} 42 | func traceWait100Continue(trace *clientTrace) {} 43 | 44 | func nop() {} 45 | 46 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 47 | return nil, nop 48 | } 49 | 50 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 51 | return ctx, nop 52 | } 53 | 54 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 55 | return req 56 | } 57 | 58 | // temporary copy of Go 1.6's private tls.Config.clone: 59 | func cloneTLSConfig(c *tls.Config) *tls.Config { 60 | return &tls.Config{ 61 | Rand: c.Rand, 62 | Time: c.Time, 63 | Certificates: c.Certificates, 64 | NameToCertificate: c.NameToCertificate, 65 | GetCertificate: c.GetCertificate, 66 | RootCAs: c.RootCAs, 67 | NextProtos: c.NextProtos, 68 | ServerName: c.ServerName, 69 | ClientAuth: c.ClientAuth, 70 | ClientCAs: c.ClientCAs, 71 | InsecureSkipVerify: c.InsecureSkipVerify, 72 | CipherSuites: c.CipherSuites, 73 | PreferServerCipherSuites: c.PreferServerCipherSuites, 74 | SessionTicketsDisabled: c.SessionTicketsDisabled, 75 | SessionTicketKey: c.SessionTicketKey, 76 | ClientSessionCache: c.ClientSessionCache, 77 | MinVersion: c.MinVersion, 78 | MaxVersion: c.MaxVersion, 79 | CurvePreferences: c.CurvePreferences, 80 | } 81 | } 82 | 83 | func (cc *ClientConn) Ping(ctx contextContext) error { 84 | return cc.ping(ctx) 85 | } 86 | 87 | func (t *Transport) idleConnTimeout() time.Duration { return 0 } 88 | -------------------------------------------------------------------------------- /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/net/idna/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package idna 4 | 5 | // This file contains definitions for interpreting the trie value of the idna 6 | // trie generated by "go run gen*.go". It is shared by both the generator 7 | // program and the resultant package. Sharing is achieved by the generator 8 | // copying gen_trieval.go to trieval.go and changing what's above this comment. 9 | 10 | // info holds information from the IDNA mapping table for a single rune. It is 11 | // the value returned by a trie lookup. In most cases, all information fits in 12 | // a 16-bit value. For mappings, this value may contain an index into a slice 13 | // with the mapped string. Such mappings can consist of the actual mapped value 14 | // or an XOR pattern to be applied to the bytes of the UTF8 encoding of the 15 | // input rune. This technique is used by the cases packages and reduces the 16 | // table size significantly. 17 | // 18 | // The per-rune values have the following format: 19 | // 20 | // if mapped { 21 | // if inlinedXOR { 22 | // 15..13 inline XOR marker 23 | // 12..11 unused 24 | // 10..3 inline XOR mask 25 | // } else { 26 | // 15..3 index into xor or mapping table 27 | // } 28 | // } else { 29 | // 15..14 unused 30 | // 13 mayNeedNorm 31 | // 12..11 attributes 32 | // 10..8 joining type 33 | // 7..3 category type 34 | // } 35 | // 2 use xor pattern 36 | // 1..0 mapped category 37 | // 38 | // See the definitions below for a more detailed description of the various 39 | // bits. 40 | type info uint16 41 | 42 | const ( 43 | catSmallMask = 0x3 44 | catBigMask = 0xF8 45 | indexShift = 3 46 | xorBit = 0x4 // interpret the index as an xor pattern 47 | inlineXOR = 0xE000 // These bits are set if the XOR pattern is inlined. 48 | 49 | joinShift = 8 50 | joinMask = 0x07 51 | 52 | // Attributes 53 | attributesMask = 0x1800 54 | viramaModifier = 0x1800 55 | modifier = 0x1000 56 | rtl = 0x0800 57 | 58 | mayNeedNorm = 0x2000 59 | ) 60 | 61 | // A category corresponds to a category defined in the IDNA mapping table. 62 | type category uint16 63 | 64 | const ( 65 | unknown category = 0 // not currently defined in unicode. 66 | mapped category = 1 67 | disallowedSTD3Mapped category = 2 68 | deviation category = 3 69 | ) 70 | 71 | const ( 72 | valid category = 0x08 73 | validNV8 category = 0x18 74 | validXV8 category = 0x28 75 | disallowed category = 0x40 76 | disallowedSTD3Valid category = 0x80 77 | ignored category = 0xC0 78 | ) 79 | 80 | // join types and additional rune information 81 | const ( 82 | joiningL = (iota + 1) 83 | joiningD 84 | joiningT 85 | joiningR 86 | 87 | //the following types are derived during processing 88 | joinZWJ 89 | joinZWNJ 90 | joinVirama 91 | numJoinTypes 92 | ) 93 | 94 | func (c info) isMapped() bool { 95 | return c&0x3 != 0 96 | } 97 | 98 | func (c info) category() category { 99 | small := c & catSmallMask 100 | if small != 0 { 101 | return category(small) 102 | } 103 | return category(c & catBigMask) 104 | } 105 | 106 | func (c info) joinType() info { 107 | if c.isMapped() { 108 | return 0 109 | } 110 | return (c >> joinShift) & joinMask 111 | } 112 | 113 | func (c info) isModifier() bool { 114 | return c&(modifier|catSmallMask) == modifier 115 | } 116 | 117 | func (c info) isViramaModifier() bool { 118 | return c&(attributesMask|catSmallMask) == viramaModifier 119 | } 120 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/trace/trace_go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 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 6 | 7 | package trace 8 | 9 | import "golang.org/x/net/context" 10 | 11 | // NewContext returns a copy of the parent context 12 | // and associates it with a Trace. 13 | func NewContext(ctx context.Context, tr Trace) context.Context { 14 | return context.WithValue(ctx, contextKey, tr) 15 | } 16 | 17 | // FromContext returns the Trace bound to the context, if any. 18 | func FromContext(ctx context.Context) (tr Trace, ok bool) { 19 | tr, ok = ctx.Value(contextKey).(Trace) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/trace/trace_go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 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 6 | 7 | package trace 8 | 9 | import "context" 10 | 11 | // NewContext returns a copy of the parent context 12 | // and associates it with a Trace. 13 | func NewContext(ctx context.Context, tr Trace) context.Context { 14 | return context.WithValue(ctx, contextKey, tr) 15 | } 16 | 17 | // FromContext returns the Trace bound to the context, if any. 18 | func FromContext(ctx context.Context) (tr Trace, ok bool) { 19 | tr, ok = ctx.Value(contextKey).(Trace) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /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.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 | "flag" 11 | "log" 12 | 13 | "golang.org/x/text/internal/gen" 14 | "golang.org/x/text/internal/triegen" 15 | "golang.org/x/text/internal/ucd" 16 | ) 17 | 18 | var outputFile = flag.String("out", "tables.go", "output file") 19 | 20 | func main() { 21 | gen.Init() 22 | gen.Repackage("gen_trieval.go", "trieval.go", "bidi") 23 | gen.Repackage("gen_ranges.go", "ranges_test.go", "bidi") 24 | 25 | genTables() 26 | } 27 | 28 | // bidiClass names and codes taken from class "bc" in 29 | // http://www.unicode.org/Public/8.0.0/ucd/PropertyValueAliases.txt 30 | var bidiClass = map[string]Class{ 31 | "AL": AL, // ArabicLetter 32 | "AN": AN, // ArabicNumber 33 | "B": B, // ParagraphSeparator 34 | "BN": BN, // BoundaryNeutral 35 | "CS": CS, // CommonSeparator 36 | "EN": EN, // EuropeanNumber 37 | "ES": ES, // EuropeanSeparator 38 | "ET": ET, // EuropeanTerminator 39 | "L": L, // LeftToRight 40 | "NSM": NSM, // NonspacingMark 41 | "ON": ON, // OtherNeutral 42 | "R": R, // RightToLeft 43 | "S": S, // SegmentSeparator 44 | "WS": WS, // WhiteSpace 45 | 46 | "FSI": Control, 47 | "PDF": Control, 48 | "PDI": Control, 49 | "LRE": Control, 50 | "LRI": Control, 51 | "LRO": Control, 52 | "RLE": Control, 53 | "RLI": Control, 54 | "RLO": Control, 55 | } 56 | 57 | func genTables() { 58 | if numClass > 0x0F { 59 | log.Fatalf("Too many Class constants (%#x > 0x0F).", numClass) 60 | } 61 | w := gen.NewCodeWriter() 62 | defer w.WriteVersionedGoFile(*outputFile, "bidi") 63 | 64 | gen.WriteUnicodeVersion(w) 65 | 66 | t := triegen.NewTrie("bidi") 67 | 68 | // Build data about bracket mapping. These bits need to be or-ed with 69 | // any other bits. 70 | orMask := map[rune]uint64{} 71 | 72 | xorMap := map[rune]int{} 73 | xorMasks := []rune{0} // First value is no-op. 74 | 75 | ucd.Parse(gen.OpenUCDFile("BidiBrackets.txt"), func(p *ucd.Parser) { 76 | r1 := p.Rune(0) 77 | r2 := p.Rune(1) 78 | xor := r1 ^ r2 79 | if _, ok := xorMap[xor]; !ok { 80 | xorMap[xor] = len(xorMasks) 81 | xorMasks = append(xorMasks, xor) 82 | } 83 | entry := uint64(xorMap[xor]) << xorMaskShift 84 | switch p.String(2) { 85 | case "o": 86 | entry |= openMask 87 | case "c", "n": 88 | default: 89 | log.Fatalf("Unknown bracket class %q.", p.String(2)) 90 | } 91 | orMask[r1] = entry 92 | }) 93 | 94 | w.WriteComment(` 95 | xorMasks contains masks to be xor-ed with brackets to get the reverse 96 | version.`) 97 | w.WriteVar("xorMasks", xorMasks) 98 | 99 | done := map[rune]bool{} 100 | 101 | insert := func(r rune, c Class) { 102 | if !done[r] { 103 | t.Insert(r, orMask[r]|uint64(c)) 104 | done[r] = true 105 | } 106 | } 107 | 108 | // Insert the derived BiDi properties. 109 | ucd.Parse(gen.OpenUCDFile("extracted/DerivedBidiClass.txt"), func(p *ucd.Parser) { 110 | r := p.Rune(0) 111 | class, ok := bidiClass[p.String(1)] 112 | if !ok { 113 | log.Fatalf("%U: Unknown BiDi class %q", r, p.String(1)) 114 | } 115 | insert(r, class) 116 | }) 117 | visitDefaults(insert) 118 | 119 | // TODO: use sparse blocks. This would reduce table size considerably 120 | // from the looks of it. 121 | 122 | sz, err := t.Gen(w) 123 | if err != nil { 124 | log.Fatal(err) 125 | } 126 | w.Size += sz 127 | } 128 | 129 | // dummy values to make methods in gen_common compile. The real versions 130 | // will be generated by this file to tables.go. 131 | var ( 132 | xorMasks []rune 133 | ) 134 | -------------------------------------------------------------------------------- /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/input.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 | import "unicode/utf8" 8 | 9 | type input struct { 10 | str string 11 | bytes []byte 12 | } 13 | 14 | func inputBytes(str []byte) input { 15 | return input{bytes: str} 16 | } 17 | 18 | func inputString(str string) input { 19 | return input{str: str} 20 | } 21 | 22 | func (in *input) setBytes(str []byte) { 23 | in.str = "" 24 | in.bytes = str 25 | } 26 | 27 | func (in *input) setString(str string) { 28 | in.str = str 29 | in.bytes = nil 30 | } 31 | 32 | func (in *input) _byte(p int) byte { 33 | if in.bytes == nil { 34 | return in.str[p] 35 | } 36 | return in.bytes[p] 37 | } 38 | 39 | func (in *input) skipASCII(p, max int) int { 40 | if in.bytes == nil { 41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ { 42 | } 43 | } else { 44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ { 45 | } 46 | } 47 | return p 48 | } 49 | 50 | func (in *input) skipContinuationBytes(p int) int { 51 | if in.bytes == nil { 52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ { 53 | } 54 | } else { 55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ { 56 | } 57 | } 58 | return p 59 | } 60 | 61 | func (in *input) appendSlice(buf []byte, b, e int) []byte { 62 | if in.bytes != nil { 63 | return append(buf, in.bytes[b:e]...) 64 | } 65 | for i := b; i < e; i++ { 66 | buf = append(buf, in.str[i]) 67 | } 68 | return buf 69 | } 70 | 71 | func (in *input) copySlice(buf []byte, b, e int) int { 72 | if in.bytes == nil { 73 | return copy(buf, in.str[b:e]) 74 | } 75 | return copy(buf, in.bytes[b:e]) 76 | } 77 | 78 | func (in *input) charinfoNFC(p int) (uint16, int) { 79 | if in.bytes == nil { 80 | return nfcData.lookupString(in.str[p:]) 81 | } 82 | return nfcData.lookup(in.bytes[p:]) 83 | } 84 | 85 | func (in *input) charinfoNFKC(p int) (uint16, int) { 86 | if in.bytes == nil { 87 | return nfkcData.lookupString(in.str[p:]) 88 | } 89 | return nfkcData.lookup(in.bytes[p:]) 90 | } 91 | 92 | func (in *input) hangul(p int) (r rune) { 93 | var size int 94 | if in.bytes == nil { 95 | if !isHangulString(in.str[p:]) { 96 | return 0 97 | } 98 | r, size = utf8.DecodeRuneInString(in.str[p:]) 99 | } else { 100 | if !isHangul(in.bytes[p:]) { 101 | return 0 102 | } 103 | r, size = utf8.DecodeRune(in.bytes[p:]) 104 | } 105 | if size != hangulUTF8Size { 106 | return 0 107 | } 108 | return r 109 | } 110 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/readwriter.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 | import "io" 8 | 9 | type normWriter struct { 10 | rb reorderBuffer 11 | w io.Writer 12 | buf []byte 13 | } 14 | 15 | // Write implements the standard write interface. If the last characters are 16 | // not at a normalization boundary, the bytes will be buffered for the next 17 | // write. The remaining bytes will be written on close. 18 | func (w *normWriter) Write(data []byte) (n int, err error) { 19 | // Process data in pieces to keep w.buf size bounded. 20 | const chunk = 4000 21 | 22 | for len(data) > 0 { 23 | // Normalize into w.buf. 24 | m := len(data) 25 | if m > chunk { 26 | m = chunk 27 | } 28 | w.rb.src = inputBytes(data[:m]) 29 | w.rb.nsrc = m 30 | w.buf = doAppend(&w.rb, w.buf, 0) 31 | data = data[m:] 32 | n += m 33 | 34 | // Write out complete prefix, save remainder. 35 | // Note that lastBoundary looks back at most 31 runes. 36 | i := lastBoundary(&w.rb.f, w.buf) 37 | if i == -1 { 38 | i = 0 39 | } 40 | if i > 0 { 41 | if _, err = w.w.Write(w.buf[:i]); err != nil { 42 | break 43 | } 44 | bn := copy(w.buf, w.buf[i:]) 45 | w.buf = w.buf[:bn] 46 | } 47 | } 48 | return n, err 49 | } 50 | 51 | // Close forces data that remains in the buffer to be written. 52 | func (w *normWriter) Close() error { 53 | if len(w.buf) > 0 { 54 | _, err := w.w.Write(w.buf) 55 | if err != nil { 56 | return err 57 | } 58 | } 59 | return nil 60 | } 61 | 62 | // Writer returns a new writer that implements Write(b) 63 | // by writing f(b) to w. The returned writer may use an 64 | // an internal buffer to maintain state across Write calls. 65 | // Calling its Close method writes any buffered data to w. 66 | func (f Form) Writer(w io.Writer) io.WriteCloser { 67 | wr := &normWriter{rb: reorderBuffer{}, w: w} 68 | wr.rb.init(f, nil) 69 | return wr 70 | } 71 | 72 | type normReader struct { 73 | rb reorderBuffer 74 | r io.Reader 75 | inbuf []byte 76 | outbuf []byte 77 | bufStart int 78 | lastBoundary int 79 | err error 80 | } 81 | 82 | // Read implements the standard read interface. 83 | func (r *normReader) Read(p []byte) (int, error) { 84 | for { 85 | if r.lastBoundary-r.bufStart > 0 { 86 | n := copy(p, r.outbuf[r.bufStart:r.lastBoundary]) 87 | r.bufStart += n 88 | if r.lastBoundary-r.bufStart > 0 { 89 | return n, nil 90 | } 91 | return n, r.err 92 | } 93 | if r.err != nil { 94 | return 0, r.err 95 | } 96 | outn := copy(r.outbuf, r.outbuf[r.lastBoundary:]) 97 | r.outbuf = r.outbuf[0:outn] 98 | r.bufStart = 0 99 | 100 | n, err := r.r.Read(r.inbuf) 101 | r.rb.src = inputBytes(r.inbuf[0:n]) 102 | r.rb.nsrc, r.err = n, err 103 | if n > 0 { 104 | r.outbuf = doAppend(&r.rb, r.outbuf, 0) 105 | } 106 | if err == io.EOF { 107 | r.lastBoundary = len(r.outbuf) 108 | } else { 109 | r.lastBoundary = lastBoundary(&r.rb.f, r.outbuf) 110 | if r.lastBoundary == -1 { 111 | r.lastBoundary = 0 112 | } 113 | } 114 | } 115 | } 116 | 117 | // Reader returns a new reader that implements Read 118 | // by reading data from r and returning f(data). 119 | func (f Form) Reader(r io.Reader) io.Reader { 120 | const chunk = 4000 121 | buf := make([]byte, chunk) 122 | rr := &normReader{rb: reorderBuffer{}, r: r, inbuf: buf} 123 | rr.rb.init(f, buf) 124 | return rr 125 | } 126 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/transform.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 | import ( 8 | "unicode/utf8" 9 | 10 | "golang.org/x/text/transform" 11 | ) 12 | 13 | // Reset implements the Reset method of the transform.Transformer interface. 14 | func (Form) Reset() {} 15 | 16 | // Transform implements the Transform method of the transform.Transformer 17 | // interface. It may need to write segments of up to MaxSegmentSize at once. 18 | // Users should either catch ErrShortDst and allow dst to grow or have dst be at 19 | // least of size MaxTransformChunkSize to be guaranteed of progress. 20 | func (f Form) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 21 | n := 0 22 | // Cap the maximum number of src bytes to check. 23 | b := src 24 | eof := atEOF 25 | if ns := len(dst); ns < len(b) { 26 | err = transform.ErrShortDst 27 | eof = false 28 | b = b[:ns] 29 | } 30 | i, ok := formTable[f].quickSpan(inputBytes(b), n, len(b), eof) 31 | n += copy(dst[n:], b[n:i]) 32 | if !ok { 33 | nDst, nSrc, err = f.transform(dst[n:], src[n:], atEOF) 34 | return nDst + n, nSrc + n, err 35 | } 36 | if n < len(src) && !atEOF { 37 | err = transform.ErrShortSrc 38 | } 39 | return n, n, err 40 | } 41 | 42 | func flushTransform(rb *reorderBuffer) bool { 43 | // Write out (must fully fit in dst, or else it is an ErrShortDst). 44 | if len(rb.out) < rb.nrune*utf8.UTFMax { 45 | return false 46 | } 47 | rb.out = rb.out[rb.flushCopy(rb.out):] 48 | return true 49 | } 50 | 51 | var errs = []error{nil, transform.ErrShortDst, transform.ErrShortSrc} 52 | 53 | // transform implements the transform.Transformer interface. It is only called 54 | // when quickSpan does not pass for a given string. 55 | func (f Form) transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 56 | // TODO: get rid of reorderBuffer. See CL 23460044. 57 | rb := reorderBuffer{} 58 | rb.init(f, src) 59 | for { 60 | // Load segment into reorder buffer. 61 | rb.setFlusher(dst[nDst:], flushTransform) 62 | end := decomposeSegment(&rb, nSrc, atEOF) 63 | if end < 0 { 64 | return nDst, nSrc, errs[-end] 65 | } 66 | nDst = len(dst) - len(rb.out) 67 | nSrc = end 68 | 69 | // Next quickSpan. 70 | end = rb.nsrc 71 | eof := atEOF 72 | if n := nSrc + len(dst) - nDst; n < end { 73 | err = transform.ErrShortDst 74 | end = n 75 | eof = false 76 | } 77 | end, ok := rb.f.quickSpan(rb.src, nSrc, end, eof) 78 | n := copy(dst[nDst:], rb.src.bytes[nSrc:end]) 79 | nSrc += n 80 | nDst += n 81 | if ok { 82 | if n < rb.nsrc && !atEOF { 83 | err = transform.ErrShortSrc 84 | } 85 | return nDst, nSrc, err 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /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/golang.org/x/text/unicode/norm/triegen.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 | // +build ignore 6 | 7 | // Trie table generator. 8 | // Used by make*tables tools to generate a go file with trie data structures 9 | // for mapping UTF-8 to a 16-bit value. All but the last byte in a UTF-8 byte 10 | // sequence are used to lookup offsets in the index table to be used for the 11 | // next byte. The last byte is used to index into a table with 16-bit values. 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "io" 18 | ) 19 | 20 | const maxSparseEntries = 16 21 | 22 | type normCompacter struct { 23 | sparseBlocks [][]uint64 24 | sparseOffset []uint16 25 | sparseCount int 26 | name string 27 | } 28 | 29 | func mostFrequentStride(a []uint64) int { 30 | counts := make(map[int]int) 31 | var v int 32 | for _, x := range a { 33 | if stride := int(x) - v; v != 0 && stride >= 0 { 34 | counts[stride]++ 35 | } 36 | v = int(x) 37 | } 38 | var maxs, maxc int 39 | for stride, cnt := range counts { 40 | if cnt > maxc || (cnt == maxc && stride < maxs) { 41 | maxs, maxc = stride, cnt 42 | } 43 | } 44 | return maxs 45 | } 46 | 47 | func countSparseEntries(a []uint64) int { 48 | stride := mostFrequentStride(a) 49 | var v, count int 50 | for _, tv := range a { 51 | if int(tv)-v != stride { 52 | if tv != 0 { 53 | count++ 54 | } 55 | } 56 | v = int(tv) 57 | } 58 | return count 59 | } 60 | 61 | func (c *normCompacter) Size(v []uint64) (sz int, ok bool) { 62 | if n := countSparseEntries(v); n <= maxSparseEntries { 63 | return (n+1)*4 + 2, true 64 | } 65 | return 0, false 66 | } 67 | 68 | func (c *normCompacter) Store(v []uint64) uint32 { 69 | h := uint32(len(c.sparseOffset)) 70 | c.sparseBlocks = append(c.sparseBlocks, v) 71 | c.sparseOffset = append(c.sparseOffset, uint16(c.sparseCount)) 72 | c.sparseCount += countSparseEntries(v) + 1 73 | return h 74 | } 75 | 76 | func (c *normCompacter) Handler() string { 77 | return c.name + "Sparse.lookup" 78 | } 79 | 80 | func (c *normCompacter) Print(w io.Writer) (retErr error) { 81 | p := func(f string, x ...interface{}) { 82 | if _, err := fmt.Fprintf(w, f, x...); retErr == nil && err != nil { 83 | retErr = err 84 | } 85 | } 86 | 87 | ls := len(c.sparseBlocks) 88 | p("// %sSparseOffset: %d entries, %d bytes\n", c.name, ls, ls*2) 89 | p("var %sSparseOffset = %#v\n\n", c.name, c.sparseOffset) 90 | 91 | ns := c.sparseCount 92 | p("// %sSparseValues: %d entries, %d bytes\n", c.name, ns, ns*4) 93 | p("var %sSparseValues = [%d]valueRange {", c.name, ns) 94 | for i, b := range c.sparseBlocks { 95 | p("\n// Block %#x, offset %#x", i, c.sparseOffset[i]) 96 | var v int 97 | stride := mostFrequentStride(b) 98 | n := countSparseEntries(b) 99 | p("\n{value:%#04x,lo:%#02x},", stride, uint8(n)) 100 | for i, nv := range b { 101 | if int(nv)-v != stride { 102 | if v != 0 { 103 | p(",hi:%#02x},", 0x80+i-1) 104 | } 105 | if nv != 0 { 106 | p("\n{value:%#04x,lo:%#02x", nv, 0x80+i) 107 | } 108 | } 109 | v = int(nv) 110 | } 111 | if v != 0 { 112 | p(",hi:%#02x},", 0x80+len(b)-1) 113 | } 114 | } 115 | p("\n}\n\n") 116 | return 117 | } 118 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/AUTHORS: -------------------------------------------------------------------------------- 1 | Google Inc. 2 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We definitely welcome your patches and contributions to gRPC! 4 | 5 | If you are new to github, please start by reading [Pull Request howto](https://help.github.com/articles/about-pull-requests/) 6 | 7 | ## Legal requirements 8 | 9 | In order to protect both you and ourselves, you will need to sign the 10 | [Contributor License Agreement](https://identity.linuxfoundation.org/projects/cncf). 11 | 12 | ## Guidelines for Pull Requests 13 | How to get your contributions merged smoothly and quickly. 14 | 15 | - Create **small PRs** that are narrowly focused on **addressing a single concern**. We often times receive PRs that are trying to fix several things at a time, but only one fix is considered acceptable, nothing gets merged and both author's & review's time is wasted. Create more PRs to address different concerns and everyone will be happy. 16 | 17 | - For speculative changes, consider opening an issue and discussing it first. If you are suggesting a behavioral or API change, consider starting with a [gRFC proposal](https://github.com/grpc/proposal). 18 | 19 | - Provide a good **PR description** as a record of **what** change is being made and **why** it was made. Link to a github issue if it exists. 20 | 21 | - Don't fix code style and formatting unless you are already changing that line to address an issue. PRs with irrelevant changes won't be merged. If you do want to fix formatting or style, do that in a separate PR. 22 | 23 | - Unless your PR is trivial, you should expect there will be reviewer comments that you'll need to address before merging. We expect you to be reasonably responsive to those comments, otherwise the PR will be closed after 2-3 weeks of inactivity. 24 | 25 | - Maintain **clean commit history** and use **meaningful commit messages**. PRs with messy commit history are difficult to review and won't be merged. Use `rebase -i upstream/master` to curate your commit history and/or to bring in latest changes from master (but avoid rebasing in the middle of a code review). 26 | 27 | - Keep your PR up to date with upstream/master (if there are merge conflicts, we can't really merge your change). 28 | 29 | - **All tests need to be passing** before your change can be merged. We recommend you **run tests locally** before creating your PR to catch breakages early on. 30 | 31 | - Exceptions to the rules can be made if there's a compelling reason for doing so. 32 | 33 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/Makefile: -------------------------------------------------------------------------------- 1 | all: test testrace 2 | 3 | deps: 4 | go get -d -v google.golang.org/grpc/... 5 | 6 | updatedeps: 7 | go get -d -v -u -f google.golang.org/grpc/... 8 | 9 | testdeps: 10 | go get -d -v -t google.golang.org/grpc/... 11 | 12 | updatetestdeps: 13 | go get -d -v -t -u -f google.golang.org/grpc/... 14 | 15 | build: deps 16 | go build google.golang.org/grpc/... 17 | 18 | proto: 19 | @ if ! which protoc > /dev/null; then \ 20 | echo "error: protoc not installed" >&2; \ 21 | exit 1; \ 22 | fi 23 | go generate google.golang.org/grpc/... 24 | 25 | test: testdeps 26 | go test -cpu 1,4 -timeout 5m google.golang.org/grpc/... 27 | 28 | testrace: testdeps 29 | go test -race -cpu 1,4 -timeout 7m google.golang.org/grpc/... 30 | 31 | clean: 32 | go clean -i google.golang.org/grpc/... 33 | 34 | .PHONY: \ 35 | all \ 36 | deps \ 37 | updatedeps \ 38 | testdeps \ 39 | updatetestdeps \ 40 | build \ 41 | proto \ 42 | test \ 43 | testrace \ 44 | clean \ 45 | coverage 46 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/README.md: -------------------------------------------------------------------------------- 1 | # gRPC-Go 2 | 3 | [![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc) [![GoReportCard](https://goreportcard.com/badge/grpc/grpc-go)](https://goreportcard.com/report/github.com/grpc/grpc-go) 4 | 5 | The Go implementation of [gRPC](https://grpc.io/): A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the [gRPC Quick Start: Go](https://grpc.io/docs/quickstart/go.html) guide. 6 | 7 | Installation 8 | ------------ 9 | 10 | To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run: 11 | 12 | ``` 13 | $ go get -u google.golang.org/grpc 14 | ``` 15 | 16 | Prerequisites 17 | ------------- 18 | 19 | This requires Go 1.6 or later. Go 1.7 will be required as of the next gRPC-Go 20 | release (1.8). 21 | 22 | Constraints 23 | ----------- 24 | The grpc package should only depend on standard Go packages and a small number of exceptions. If your contribution introduces new dependencies which are NOT in the [list](http://godoc.org/google.golang.org/grpc?imports), you need a discussion with gRPC-Go authors and consultants. 25 | 26 | Documentation 27 | ------------- 28 | See [API documentation](https://godoc.org/google.golang.org/grpc) for package and API descriptions and find examples in the [examples directory](examples/). 29 | 30 | Performance 31 | ----------- 32 | See the current benchmarks for some of the languages supported in [this dashboard](https://performance-dot-grpc-testing.appspot.com/explore?dashboard=5652536396611584&widget=490377658&container=1286539696). 33 | 34 | Status 35 | ------ 36 | General Availability [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages). 37 | 38 | FAQ 39 | --- 40 | 41 | #### Compiling error, undefined: grpc.SupportPackageIsVersion 42 | 43 | Please update proto package, gRPC package and rebuild the proto files: 44 | - `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}` 45 | - `go get -u google.golang.org/grpc` 46 | - `protoc --go_out=plugins=grpc:. *.proto` 47 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/backoff.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "math/rand" 23 | "time" 24 | ) 25 | 26 | // DefaultBackoffConfig uses values specified for backoff in 27 | // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md. 28 | var DefaultBackoffConfig = BackoffConfig{ 29 | MaxDelay: 120 * time.Second, 30 | baseDelay: 1.0 * time.Second, 31 | factor: 1.6, 32 | jitter: 0.2, 33 | } 34 | 35 | // backoffStrategy defines the methodology for backing off after a grpc 36 | // connection failure. 37 | // 38 | // This is unexported until the gRPC project decides whether or not to allow 39 | // alternative backoff strategies. Once a decision is made, this type and its 40 | // method may be exported. 41 | type backoffStrategy interface { 42 | // backoff returns the amount of time to wait before the next retry given 43 | // the number of consecutive failures. 44 | backoff(retries int) time.Duration 45 | } 46 | 47 | // BackoffConfig defines the parameters for the default gRPC backoff strategy. 48 | type BackoffConfig struct { 49 | // MaxDelay is the upper bound of backoff delay. 50 | MaxDelay time.Duration 51 | 52 | // TODO(stevvooe): The following fields are not exported, as allowing 53 | // changes would violate the current gRPC specification for backoff. If 54 | // gRPC decides to allow more interesting backoff strategies, these fields 55 | // may be opened up in the future. 56 | 57 | // baseDelay is the amount of time to wait before retrying after the first 58 | // failure. 59 | baseDelay time.Duration 60 | 61 | // factor is applied to the backoff after each retry. 62 | factor float64 63 | 64 | // jitter provides a range to randomize backoff delays. 65 | jitter float64 66 | } 67 | 68 | func setDefaults(bc *BackoffConfig) { 69 | md := bc.MaxDelay 70 | *bc = DefaultBackoffConfig 71 | 72 | if md > 0 { 73 | bc.MaxDelay = md 74 | } 75 | } 76 | 77 | func (bc BackoffConfig) backoff(retries int) time.Duration { 78 | if retries == 0 { 79 | return bc.baseDelay 80 | } 81 | backoff, max := float64(bc.baseDelay), float64(bc.MaxDelay) 82 | for backoff < max && retries > 0 { 83 | backoff *= bc.factor 84 | retries-- 85 | } 86 | if backoff > max { 87 | backoff = max 88 | } 89 | // Randomize backoff delays so that if a cluster of requests start at 90 | // the same time, they won't operate in lockstep. 91 | backoff *= 1 + bc.jitter*(rand.Float64()*2-1) 92 | if backoff < 0 { 93 | return 0 94 | } 95 | return time.Duration(backoff) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/balancer/base/base.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package base defines a balancer base that can be used to build balancers with 20 | // different picking algorithms. 21 | // 22 | // The base balancer creates a new SubConn for each resolved address. The 23 | // provided picker will only be notified about READY SubConns. 24 | // 25 | // This package is the base of round_robin balancer, its purpose is to be used 26 | // to build round_robin like balancers with complex picking algorithms. 27 | // Balancers with more complicated logic should try to implement a balancer 28 | // builder from scratch. 29 | // 30 | // All APIs in this package are experimental. 31 | package base 32 | 33 | import ( 34 | "google.golang.org/grpc/balancer" 35 | "google.golang.org/grpc/resolver" 36 | ) 37 | 38 | // PickerBuilder creates balancer.Picker. 39 | type PickerBuilder interface { 40 | // Build takes a slice of ready SubConns, and returns a picker that will be 41 | // used by gRPC to pick a SubConn. 42 | Build(readySCs map[resolver.Address]balancer.SubConn) balancer.Picker 43 | } 44 | 45 | // NewBalancerBuilder returns a balancer builder. The balancers 46 | // built by this builder will use the picker builder to build pickers. 47 | func NewBalancerBuilder(name string, pb PickerBuilder) balancer.Builder { 48 | return &baseBuilder{ 49 | name: name, 50 | pickerBuilder: pb, 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/balancer/roundrobin/roundrobin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package roundrobin defines a roundrobin balancer. Roundrobin balancer is 20 | // installed as one of the default balancers in gRPC, users don't need to 21 | // explicitly install this balancer. 22 | package roundrobin 23 | 24 | import ( 25 | "sync" 26 | 27 | "golang.org/x/net/context" 28 | "google.golang.org/grpc/balancer" 29 | "google.golang.org/grpc/balancer/base" 30 | "google.golang.org/grpc/grpclog" 31 | "google.golang.org/grpc/resolver" 32 | ) 33 | 34 | // Name is the name of round_robin balancer. 35 | const Name = "round_robin" 36 | 37 | // newBuilder creates a new roundrobin balancer builder. 38 | func newBuilder() balancer.Builder { 39 | return base.NewBalancerBuilder(Name, &rrPickerBuilder{}) 40 | } 41 | 42 | func init() { 43 | balancer.Register(newBuilder()) 44 | } 45 | 46 | type rrPickerBuilder struct{} 47 | 48 | func (*rrPickerBuilder) Build(readySCs map[resolver.Address]balancer.SubConn) balancer.Picker { 49 | grpclog.Infof("roundrobinPicker: newPicker called with readySCs: %v", readySCs) 50 | var scs []balancer.SubConn 51 | for _, sc := range readySCs { 52 | scs = append(scs, sc) 53 | } 54 | return &rrPicker{ 55 | subConns: scs, 56 | } 57 | } 58 | 59 | type rrPicker struct { 60 | // subConns is the snapshot of the roundrobin balancer when this picker was 61 | // created. The slice is immutable. Each Get() will do a round robin 62 | // selection from it and return the selected SubConn. 63 | subConns []balancer.SubConn 64 | 65 | mu sync.Mutex 66 | next int 67 | } 68 | 69 | func (p *rrPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { 70 | if len(p.subConns) <= 0 { 71 | return nil, nil, balancer.ErrNoSubConnAvailable 72 | } 73 | 74 | p.mu.Lock() 75 | sc := p.subConns[p.next] 76 | p.next = (p.next + 1) % len(p.subConns) 77 | p.mu.Unlock() 78 | return sc, nil, nil 79 | } 80 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/call.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "golang.org/x/net/context" 23 | ) 24 | 25 | // Invoke sends the RPC request on the wire and returns after response is 26 | // received. This is typically called by generated code. 27 | // 28 | // All errors returned by Invoke are compatible with the status package. 29 | func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...CallOption) error { 30 | if cc.dopts.unaryInt != nil { 31 | return cc.dopts.unaryInt(ctx, method, args, reply, cc, invoke, opts...) 32 | } 33 | return invoke(ctx, method, args, reply, cc, opts...) 34 | } 35 | 36 | // Invoke sends the RPC request on the wire and returns after response is 37 | // received. This is typically called by generated code. 38 | // 39 | // DEPRECATED: Use ClientConn.Invoke instead. 40 | func Invoke(ctx context.Context, method string, args, reply interface{}, cc *ClientConn, opts ...CallOption) error { 41 | return cc.Invoke(ctx, method, args, reply, opts...) 42 | } 43 | 44 | var unaryStreamDesc = &StreamDesc{ServerStreams: false, ClientStreams: false} 45 | 46 | func invoke(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error { 47 | // TODO: implement retries in clientStream and make this simply 48 | // newClientStream, SendMsg, RecvMsg. 49 | firstAttempt := true 50 | for { 51 | csInt, err := newClientStream(ctx, unaryStreamDesc, cc, method, opts...) 52 | if err != nil { 53 | return err 54 | } 55 | cs := csInt.(*clientStream) 56 | if err := cs.SendMsg(req); err != nil { 57 | if !cs.c.failFast && cs.s.Unprocessed() && firstAttempt { 58 | // TODO: Add a field to header for grpc-transparent-retry-attempts 59 | firstAttempt = false 60 | continue 61 | } 62 | return err 63 | } 64 | if err := cs.RecvMsg(reply); err != nil { 65 | if !cs.c.failFast && cs.s.Unprocessed() && firstAttempt { 66 | // TODO: Add a field to header for grpc-transparent-retry-attempts 67 | firstAttempt = false 68 | continue 69 | } 70 | return err 71 | } 72 | return nil 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/codec.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "google.golang.org/grpc/encoding" 23 | _ "google.golang.org/grpc/encoding/proto" // to register the Codec for "proto" 24 | ) 25 | 26 | // baseCodec contains the functionality of both Codec and encoding.Codec, but 27 | // omits the name/string, which vary between the two and are not needed for 28 | // anything besides the registry in the encoding package. 29 | type baseCodec interface { 30 | Marshal(v interface{}) ([]byte, error) 31 | Unmarshal(data []byte, v interface{}) error 32 | } 33 | 34 | var _ baseCodec = Codec(nil) 35 | var _ baseCodec = encoding.Codec(nil) 36 | 37 | // Codec defines the interface gRPC uses to encode and decode messages. 38 | // Note that implementations of this interface must be thread safe; 39 | // a Codec's methods can be called from concurrent goroutines. 40 | // 41 | // Deprecated: use encoding.Codec instead. 42 | type Codec interface { 43 | // Marshal returns the wire format of v. 44 | Marshal(v interface{}) ([]byte, error) 45 | // Unmarshal parses the wire format into v. 46 | Unmarshal(data []byte, v interface{}) error 47 | // String returns the name of the Codec implementation. This is unused by 48 | // gRPC. 49 | String() string 50 | } 51 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/codegen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script serves as an example to demonstrate how to generate the gRPC-Go 4 | # interface and the related messages from .proto file. 5 | # 6 | # It assumes the installation of i) Google proto buffer compiler at 7 | # https://github.com/google/protobuf (after v2.6.1) and ii) the Go codegen 8 | # plugin at https://github.com/golang/protobuf (after 2015-02-20). If you have 9 | # not, please install them first. 10 | # 11 | # We recommend running this script at $GOPATH/src. 12 | # 13 | # If this is not what you need, feel free to make your own scripts. Again, this 14 | # script is for demonstration purpose. 15 | # 16 | proto=$1 17 | protoc --go_out=plugins=grpc:. $proto 18 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/codes/code_string.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package codes 20 | 21 | import "strconv" 22 | 23 | func (c Code) String() string { 24 | switch c { 25 | case OK: 26 | return "OK" 27 | case Canceled: 28 | return "Canceled" 29 | case Unknown: 30 | return "Unknown" 31 | case InvalidArgument: 32 | return "InvalidArgument" 33 | case DeadlineExceeded: 34 | return "DeadlineExceeded" 35 | case NotFound: 36 | return "NotFound" 37 | case AlreadyExists: 38 | return "AlreadyExists" 39 | case PermissionDenied: 40 | return "PermissionDenied" 41 | case ResourceExhausted: 42 | return "ResourceExhausted" 43 | case FailedPrecondition: 44 | return "FailedPrecondition" 45 | case Aborted: 46 | return "Aborted" 47 | case OutOfRange: 48 | return "OutOfRange" 49 | case Unimplemented: 50 | return "Unimplemented" 51 | case Internal: 52 | return "Internal" 53 | case Unavailable: 54 | return "Unavailable" 55 | case DataLoss: 56 | return "DataLoss" 57 | case Unauthenticated: 58 | return "Unauthenticated" 59 | default: 60 | return "Code(" + strconv.FormatInt(int64(c), 10) + ")" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/connectivity/connectivity.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package connectivity defines connectivity semantics. 20 | // For details, see https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md. 21 | // All APIs in this package are experimental. 22 | package connectivity 23 | 24 | import ( 25 | "golang.org/x/net/context" 26 | "google.golang.org/grpc/grpclog" 27 | ) 28 | 29 | // State indicates the state of connectivity. 30 | // It can be the state of a ClientConn or SubConn. 31 | type State int 32 | 33 | func (s State) String() string { 34 | switch s { 35 | case Idle: 36 | return "IDLE" 37 | case Connecting: 38 | return "CONNECTING" 39 | case Ready: 40 | return "READY" 41 | case TransientFailure: 42 | return "TRANSIENT_FAILURE" 43 | case Shutdown: 44 | return "SHUTDOWN" 45 | default: 46 | grpclog.Errorf("unknown connectivity state: %d", s) 47 | return "Invalid-State" 48 | } 49 | } 50 | 51 | const ( 52 | // Idle indicates the ClientConn is idle. 53 | Idle State = iota 54 | // Connecting indicates the ClienConn is connecting. 55 | Connecting 56 | // Ready indicates the ClientConn is ready for work. 57 | Ready 58 | // TransientFailure indicates the ClientConn has seen a failure but expects to recover. 59 | TransientFailure 60 | // Shutdown indicates the ClientConn has started shutting down. 61 | Shutdown 62 | ) 63 | 64 | // Reporter reports the connectivity states. 65 | type Reporter interface { 66 | // CurrentState returns the current state of the reporter. 67 | CurrentState() State 68 | // WaitForStateChange blocks until the reporter's state is different from the given state, 69 | // and returns true. 70 | // It returns false if <-ctx.Done() can proceed (ctx got timeout or got canceled). 71 | WaitForStateChange(context.Context, State) bool 72 | } 73 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/credentials/credentials_util_go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | // +build !go1.8 3 | 4 | /* 5 | * 6 | * Copyright 2016 gRPC authors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | package credentials 23 | 24 | import ( 25 | "crypto/tls" 26 | ) 27 | 28 | // cloneTLSConfig returns a shallow clone of the exported 29 | // fields of cfg, ignoring the unexported sync.Once, which 30 | // contains a mutex and must not be copied. 31 | // 32 | // If cfg is nil, a new zero tls.Config is returned. 33 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 34 | if cfg == nil { 35 | return &tls.Config{} 36 | } 37 | return &tls.Config{ 38 | Rand: cfg.Rand, 39 | Time: cfg.Time, 40 | Certificates: cfg.Certificates, 41 | NameToCertificate: cfg.NameToCertificate, 42 | GetCertificate: cfg.GetCertificate, 43 | RootCAs: cfg.RootCAs, 44 | NextProtos: cfg.NextProtos, 45 | ServerName: cfg.ServerName, 46 | ClientAuth: cfg.ClientAuth, 47 | ClientCAs: cfg.ClientCAs, 48 | InsecureSkipVerify: cfg.InsecureSkipVerify, 49 | CipherSuites: cfg.CipherSuites, 50 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 51 | SessionTicketsDisabled: cfg.SessionTicketsDisabled, 52 | SessionTicketKey: cfg.SessionTicketKey, 53 | ClientSessionCache: cfg.ClientSessionCache, 54 | MinVersion: cfg.MinVersion, 55 | MaxVersion: cfg.MaxVersion, 56 | CurvePreferences: cfg.CurvePreferences, 57 | DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled, 58 | Renegotiation: cfg.Renegotiation, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/credentials/credentials_util_go18.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package credentials 22 | 23 | import ( 24 | "crypto/tls" 25 | ) 26 | 27 | // cloneTLSConfig returns a shallow clone of the exported 28 | // fields of cfg, ignoring the unexported sync.Once, which 29 | // contains a mutex and must not be copied. 30 | // 31 | // If cfg is nil, a new zero tls.Config is returned. 32 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 33 | if cfg == nil { 34 | return &tls.Config{} 35 | } 36 | 37 | return cfg.Clone() 38 | } 39 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/credentials/credentials_util_pre_go17.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package credentials 22 | 23 | import ( 24 | "crypto/tls" 25 | ) 26 | 27 | // cloneTLSConfig returns a shallow clone of the exported 28 | // fields of cfg, ignoring the unexported sync.Once, which 29 | // contains a mutex and must not be copied. 30 | // 31 | // If cfg is nil, a new zero tls.Config is returned. 32 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 33 | if cfg == nil { 34 | return &tls.Config{} 35 | } 36 | return &tls.Config{ 37 | Rand: cfg.Rand, 38 | Time: cfg.Time, 39 | Certificates: cfg.Certificates, 40 | NameToCertificate: cfg.NameToCertificate, 41 | GetCertificate: cfg.GetCertificate, 42 | RootCAs: cfg.RootCAs, 43 | NextProtos: cfg.NextProtos, 44 | ServerName: cfg.ServerName, 45 | ClientAuth: cfg.ClientAuth, 46 | ClientCAs: cfg.ClientCAs, 47 | InsecureSkipVerify: cfg.InsecureSkipVerify, 48 | CipherSuites: cfg.CipherSuites, 49 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 50 | SessionTicketsDisabled: cfg.SessionTicketsDisabled, 51 | SessionTicketKey: cfg.SessionTicketKey, 52 | ClientSessionCache: cfg.ClientSessionCache, 53 | MinVersion: cfg.MinVersion, 54 | MaxVersion: cfg.MaxVersion, 55 | CurvePreferences: cfg.CurvePreferences, 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | /* 20 | Package grpc implements an RPC system called gRPC. 21 | 22 | See grpc.io for more information about gRPC. 23 | */ 24 | package grpc // import "google.golang.org/grpc" 25 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/encoding/proto/proto.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package proto defines the protobuf codec. Importing this package will 20 | // register the codec. 21 | package proto 22 | 23 | import ( 24 | "math" 25 | "sync" 26 | 27 | "github.com/golang/protobuf/proto" 28 | "google.golang.org/grpc/encoding" 29 | ) 30 | 31 | // Name is the name registered for the proto compressor. 32 | const Name = "proto" 33 | 34 | func init() { 35 | encoding.RegisterCodec(codec{}) 36 | } 37 | 38 | // codec is a Codec implementation with protobuf. It is the default codec for gRPC. 39 | type codec struct{} 40 | 41 | type cachedProtoBuffer struct { 42 | lastMarshaledSize uint32 43 | proto.Buffer 44 | } 45 | 46 | func capToMaxInt32(val int) uint32 { 47 | if val > math.MaxInt32 { 48 | return uint32(math.MaxInt32) 49 | } 50 | return uint32(val) 51 | } 52 | 53 | func marshal(v interface{}, cb *cachedProtoBuffer) ([]byte, error) { 54 | protoMsg := v.(proto.Message) 55 | newSlice := make([]byte, 0, cb.lastMarshaledSize) 56 | 57 | cb.SetBuf(newSlice) 58 | cb.Reset() 59 | if err := cb.Marshal(protoMsg); err != nil { 60 | return nil, err 61 | } 62 | out := cb.Bytes() 63 | cb.lastMarshaledSize = capToMaxInt32(len(out)) 64 | return out, nil 65 | } 66 | 67 | func (codec) Marshal(v interface{}) ([]byte, error) { 68 | if pm, ok := v.(proto.Marshaler); ok { 69 | // object can marshal itself, no need for buffer 70 | return pm.Marshal() 71 | } 72 | 73 | cb := protoBufferPool.Get().(*cachedProtoBuffer) 74 | out, err := marshal(v, cb) 75 | 76 | // put back buffer and lose the ref to the slice 77 | cb.SetBuf(nil) 78 | protoBufferPool.Put(cb) 79 | return out, err 80 | } 81 | 82 | func (codec) Unmarshal(data []byte, v interface{}) error { 83 | protoMsg := v.(proto.Message) 84 | protoMsg.Reset() 85 | 86 | if pu, ok := protoMsg.(proto.Unmarshaler); ok { 87 | // object can unmarshal itself, no need for buffer 88 | return pu.Unmarshal(data) 89 | } 90 | 91 | cb := protoBufferPool.Get().(*cachedProtoBuffer) 92 | cb.SetBuf(data) 93 | err := cb.Unmarshal(protoMsg) 94 | cb.SetBuf(nil) 95 | protoBufferPool.Put(cb) 96 | return err 97 | } 98 | 99 | func (codec) Name() string { 100 | return Name 101 | } 102 | 103 | var protoBufferPool = &sync.Pool{ 104 | New: func() interface{} { 105 | return &cachedProtoBuffer{ 106 | Buffer: proto.Buffer{}, 107 | lastMarshaledSize: 16, 108 | } 109 | }, 110 | } 111 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/go16.go: -------------------------------------------------------------------------------- 1 | // +build go1.6,!go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package grpc 22 | 23 | import ( 24 | "fmt" 25 | "io" 26 | "net" 27 | "net/http" 28 | "os" 29 | 30 | "golang.org/x/net/context" 31 | "google.golang.org/grpc/codes" 32 | "google.golang.org/grpc/status" 33 | "google.golang.org/grpc/transport" 34 | ) 35 | 36 | // dialContext connects to the address on the named network. 37 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 38 | return (&net.Dialer{Cancel: ctx.Done()}).Dial(network, address) 39 | } 40 | 41 | func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error { 42 | req.Cancel = ctx.Done() 43 | if err := req.Write(conn); err != nil { 44 | return fmt.Errorf("failed to write the HTTP request: %v", err) 45 | } 46 | return nil 47 | } 48 | 49 | // toRPCErr converts an error into an error from the status package. 50 | func toRPCErr(err error) error { 51 | if _, ok := status.FromError(err); ok { 52 | return err 53 | } 54 | switch e := err.(type) { 55 | case transport.StreamError: 56 | return status.Error(e.Code, e.Desc) 57 | case transport.ConnectionError: 58 | return status.Error(codes.Unavailable, e.Desc) 59 | default: 60 | switch err { 61 | case context.DeadlineExceeded: 62 | return status.Error(codes.DeadlineExceeded, err.Error()) 63 | case context.Canceled: 64 | return status.Error(codes.Canceled, err.Error()) 65 | case ErrClientConnClosing: 66 | return status.Error(codes.FailedPrecondition, err.Error()) 67 | } 68 | } 69 | return status.Error(codes.Unknown, err.Error()) 70 | } 71 | 72 | // convertCode converts a standard Go error into its canonical code. Note that 73 | // this is only used to translate the error returned by the server applications. 74 | func convertCode(err error) codes.Code { 75 | switch err { 76 | case nil: 77 | return codes.OK 78 | case io.EOF: 79 | return codes.OutOfRange 80 | case io.ErrClosedPipe, io.ErrNoProgress, io.ErrShortBuffer, io.ErrShortWrite, io.ErrUnexpectedEOF: 81 | return codes.FailedPrecondition 82 | case os.ErrInvalid: 83 | return codes.InvalidArgument 84 | case context.Canceled: 85 | return codes.Canceled 86 | case context.DeadlineExceeded: 87 | return codes.DeadlineExceeded 88 | } 89 | switch { 90 | case os.IsExist(err): 91 | return codes.AlreadyExists 92 | case os.IsNotExist(err): 93 | return codes.NotFound 94 | case os.IsPermission(err): 95 | return codes.PermissionDenied 96 | } 97 | return codes.Unknown 98 | } 99 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package grpc 22 | 23 | import ( 24 | "context" 25 | "fmt" 26 | "io" 27 | "net" 28 | "net/http" 29 | "os" 30 | 31 | netctx "golang.org/x/net/context" 32 | "google.golang.org/grpc/codes" 33 | "google.golang.org/grpc/status" 34 | "google.golang.org/grpc/transport" 35 | ) 36 | 37 | // dialContext connects to the address on the named network. 38 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 39 | return (&net.Dialer{}).DialContext(ctx, network, address) 40 | } 41 | 42 | func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error { 43 | req = req.WithContext(ctx) 44 | if err := req.Write(conn); err != nil { 45 | return fmt.Errorf("failed to write the HTTP request: %v", err) 46 | } 47 | return nil 48 | } 49 | 50 | // toRPCErr converts an error into an error from the status package. 51 | func toRPCErr(err error) error { 52 | if _, ok := status.FromError(err); ok { 53 | return err 54 | } 55 | switch e := err.(type) { 56 | case transport.StreamError: 57 | return status.Error(e.Code, e.Desc) 58 | case transport.ConnectionError: 59 | return status.Error(codes.Unavailable, e.Desc) 60 | default: 61 | switch err { 62 | case context.DeadlineExceeded, netctx.DeadlineExceeded: 63 | return status.Error(codes.DeadlineExceeded, err.Error()) 64 | case context.Canceled, netctx.Canceled: 65 | return status.Error(codes.Canceled, err.Error()) 66 | case ErrClientConnClosing: 67 | return status.Error(codes.FailedPrecondition, err.Error()) 68 | } 69 | } 70 | return status.Error(codes.Unknown, err.Error()) 71 | } 72 | 73 | // convertCode converts a standard Go error into its canonical code. Note that 74 | // this is only used to translate the error returned by the server applications. 75 | func convertCode(err error) codes.Code { 76 | switch err { 77 | case nil: 78 | return codes.OK 79 | case io.EOF: 80 | return codes.OutOfRange 81 | case io.ErrClosedPipe, io.ErrNoProgress, io.ErrShortBuffer, io.ErrShortWrite, io.ErrUnexpectedEOF: 82 | return codes.FailedPrecondition 83 | case os.ErrInvalid: 84 | return codes.InvalidArgument 85 | case context.Canceled, netctx.Canceled: 86 | return codes.Canceled 87 | case context.DeadlineExceeded, netctx.DeadlineExceeded: 88 | return codes.DeadlineExceeded 89 | } 90 | switch { 91 | case os.IsExist(err): 92 | return codes.AlreadyExists 93 | case os.IsNotExist(err): 94 | return codes.NotFound 95 | case os.IsPermission(err): 96 | return codes.PermissionDenied 97 | } 98 | return codes.Unknown 99 | } 100 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/grpclb_util.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "google.golang.org/grpc/balancer" 23 | "google.golang.org/grpc/resolver" 24 | ) 25 | 26 | // The parent ClientConn should re-resolve when grpclb loses connection to the 27 | // remote balancer. When the ClientConn inside grpclb gets a TransientFailure, 28 | // it calls lbManualResolver.ResolveNow(), which calls parent ClientConn's 29 | // ResolveNow, and eventually results in re-resolve happening in parent 30 | // ClientConn's resolver (DNS for example). 31 | // 32 | // parent 33 | // ClientConn 34 | // +-----------------------------------------------------------------+ 35 | // | parent +---------------------------------+ | 36 | // | DNS ClientConn | grpclb | | 37 | // | resolver balancerWrapper | | | 38 | // | + + | grpclb grpclb | | 39 | // | | | | ManualResolver ClientConn | | 40 | // | | | | + + | | 41 | // | | | | | | Transient | | 42 | // | | | | | | Failure | | 43 | // | | | | | <--------- | | | 44 | // | | | <--------------- | ResolveNow | | | 45 | // | | <--------- | ResolveNow | | | | | 46 | // | | ResolveNow | | | | | | 47 | // | | | | | | | | 48 | // | + + | + + | | 49 | // | +---------------------------------+ | 50 | // +-----------------------------------------------------------------+ 51 | 52 | // lbManualResolver is used by the ClientConn inside grpclb. It's a manual 53 | // resolver with a special ResolveNow() function. 54 | // 55 | // When ResolveNow() is called, it calls ResolveNow() on the parent ClientConn, 56 | // so when grpclb client lose contact with remote balancers, the parent 57 | // ClientConn's resolver will re-resolve. 58 | type lbManualResolver struct { 59 | scheme string 60 | ccr resolver.ClientConn 61 | 62 | ccb balancer.ClientConn 63 | } 64 | 65 | func (r *lbManualResolver) Build(_ resolver.Target, cc resolver.ClientConn, _ resolver.BuildOption) (resolver.Resolver, error) { 66 | r.ccr = cc 67 | return r, nil 68 | } 69 | 70 | func (r *lbManualResolver) Scheme() string { 71 | return r.scheme 72 | } 73 | 74 | // ResolveNow calls resolveNow on the parent ClientConn. 75 | func (r *lbManualResolver) ResolveNow(o resolver.ResolveNowOption) { 76 | r.ccb.ResolveNow(o) 77 | } 78 | 79 | // Close is a noop for Resolver. 80 | func (*lbManualResolver) Close() {} 81 | 82 | // NewAddress calls cc.NewAddress. 83 | func (r *lbManualResolver) NewAddress(addrs []resolver.Address) { 84 | r.ccr.NewAddress(addrs) 85 | } 86 | 87 | // NewServiceConfig calls cc.NewServiceConfig. 88 | func (r *lbManualResolver) NewServiceConfig(sc string) { 89 | r.ccr.NewServiceConfig(sc) 90 | } 91 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/grpclog/logger.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpclog 20 | 21 | // Logger mimics golang's standard Logger as an interface. 22 | // Deprecated: use LoggerV2. 23 | type Logger interface { 24 | Fatal(args ...interface{}) 25 | Fatalf(format string, args ...interface{}) 26 | Fatalln(args ...interface{}) 27 | Print(args ...interface{}) 28 | Printf(format string, args ...interface{}) 29 | Println(args ...interface{}) 30 | } 31 | 32 | // SetLogger sets the logger that is used in grpc. Call only from 33 | // init() functions. 34 | // Deprecated: use SetLoggerV2. 35 | func SetLogger(l Logger) { 36 | logger = &loggerWrapper{Logger: l} 37 | } 38 | 39 | // loggerWrapper wraps Logger into a LoggerV2. 40 | type loggerWrapper struct { 41 | Logger 42 | } 43 | 44 | func (g *loggerWrapper) Info(args ...interface{}) { 45 | g.Logger.Print(args...) 46 | } 47 | 48 | func (g *loggerWrapper) Infoln(args ...interface{}) { 49 | g.Logger.Println(args...) 50 | } 51 | 52 | func (g *loggerWrapper) Infof(format string, args ...interface{}) { 53 | g.Logger.Printf(format, args...) 54 | } 55 | 56 | func (g *loggerWrapper) Warning(args ...interface{}) { 57 | g.Logger.Print(args...) 58 | } 59 | 60 | func (g *loggerWrapper) Warningln(args ...interface{}) { 61 | g.Logger.Println(args...) 62 | } 63 | 64 | func (g *loggerWrapper) Warningf(format string, args ...interface{}) { 65 | g.Logger.Printf(format, args...) 66 | } 67 | 68 | func (g *loggerWrapper) Error(args ...interface{}) { 69 | g.Logger.Print(args...) 70 | } 71 | 72 | func (g *loggerWrapper) Errorln(args ...interface{}) { 73 | g.Logger.Println(args...) 74 | } 75 | 76 | func (g *loggerWrapper) Errorf(format string, args ...interface{}) { 77 | g.Logger.Printf(format, args...) 78 | } 79 | 80 | func (g *loggerWrapper) V(l int) bool { 81 | // Returns true for all verbose level. 82 | return true 83 | } 84 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | // Package internal contains gRPC-internal code for testing, to avoid polluting 19 | // the godoc of the top-level grpc package. 20 | package internal 21 | 22 | // TestingUseHandlerImpl enables the http.Handler-based server implementation. 23 | // It must be called before Serve and requires TLS credentials. 24 | // 25 | // The provided grpcServer must be of type *grpc.Server. It is untyped 26 | // for circular dependency reasons. 27 | var TestingUseHandlerImpl func(grpcServer interface{}) 28 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/keepalive/keepalive.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package keepalive defines configurable parameters for point-to-point healthcheck. 20 | package keepalive 21 | 22 | import ( 23 | "time" 24 | ) 25 | 26 | // ClientParameters is used to set keepalive parameters on the client-side. 27 | // These configure how the client will actively probe to notice when a connection is broken 28 | // and send pings so intermediaries will be aware of the liveness of the connection. 29 | // Make sure these parameters are set in coordination with the keepalive policy on the server, 30 | // as incompatible settings can result in closing of connection. 31 | type ClientParameters struct { 32 | // After a duration of this time if the client doesn't see any activity it pings the server to see if the transport is still alive. 33 | Time time.Duration // The current default value is infinity. 34 | // After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that 35 | // the connection is closed. 36 | Timeout time.Duration // The current default value is 20 seconds. 37 | // If true, client runs keepalive checks even with no active RPCs. 38 | PermitWithoutStream bool // false by default. 39 | } 40 | 41 | // ServerParameters is used to set keepalive and max-age parameters on the server-side. 42 | type ServerParameters struct { 43 | // MaxConnectionIdle is a duration for the amount of time after which an idle connection would be closed by sending a GoAway. 44 | // Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment. 45 | MaxConnectionIdle time.Duration // The current default value is infinity. 46 | // MaxConnectionAge is a duration for the maximum amount of time a connection may exist before it will be closed by sending a GoAway. 47 | // A random jitter of +/-10% will be added to MaxConnectionAge to spread out connection storms. 48 | MaxConnectionAge time.Duration // The current default value is infinity. 49 | // MaxConnectinoAgeGrace is an additive period after MaxConnectionAge after which the connection will be forcibly closed. 50 | MaxConnectionAgeGrace time.Duration // The current default value is infinity. 51 | // After a duration of this time if the server doesn't see any activity it pings the client to see if the transport is still alive. 52 | Time time.Duration // The current default value is 2 hours. 53 | // After having pinged for keepalive check, the server waits for a duration of Timeout and if no activity is seen even after that 54 | // the connection is closed. 55 | Timeout time.Duration // The current default value is 20 seconds. 56 | } 57 | 58 | // EnforcementPolicy is used to set keepalive enforcement policy on the server-side. 59 | // Server will close connection with a client that violates this policy. 60 | type EnforcementPolicy struct { 61 | // MinTime is the minimum amount of time a client should wait before sending a keepalive ping. 62 | MinTime time.Duration // The current default value is 5 minutes. 63 | // If true, server expects keepalive pings even when there are no active streams(RPCs). 64 | PermitWithoutStream bool // false by default. 65 | } 66 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/naming/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.6,!go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package naming 22 | 23 | import ( 24 | "net" 25 | 26 | "golang.org/x/net/context" 27 | ) 28 | 29 | var ( 30 | lookupHost = func(ctx context.Context, host string) ([]string, error) { return net.LookupHost(host) } 31 | lookupSRV = func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) { 32 | return net.LookupSRV(service, proto, name) 33 | } 34 | ) 35 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/naming/go18.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package naming 22 | 23 | import "net" 24 | 25 | var ( 26 | lookupHost = net.DefaultResolver.LookupHost 27 | lookupSRV = net.DefaultResolver.LookupSRV 28 | ) 29 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/naming/naming.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package naming defines the naming API and related data structures for gRPC. 20 | // The interface is EXPERIMENTAL and may be suject to change. 21 | package naming 22 | 23 | // Operation defines the corresponding operations for a name resolution change. 24 | type Operation uint8 25 | 26 | const ( 27 | // Add indicates a new address is added. 28 | Add Operation = iota 29 | // Delete indicates an exisiting address is deleted. 30 | Delete 31 | ) 32 | 33 | // Update defines a name resolution update. Notice that it is not valid having both 34 | // empty string Addr and nil Metadata in an Update. 35 | type Update struct { 36 | // Op indicates the operation of the update. 37 | Op Operation 38 | // Addr is the updated address. It is empty string if there is no address update. 39 | Addr string 40 | // Metadata is the updated metadata. It is nil if there is no metadata update. 41 | // Metadata is not required for a custom naming implementation. 42 | Metadata interface{} 43 | } 44 | 45 | // Resolver creates a Watcher for a target to track its resolution changes. 46 | type Resolver interface { 47 | // Resolve creates a Watcher for target. 48 | Resolve(target string) (Watcher, error) 49 | } 50 | 51 | // Watcher watches for the updates on the specified target. 52 | type Watcher interface { 53 | // Next blocks until an update or error happens. It may return one or more 54 | // updates. The first call should get the full set of the results. It should 55 | // return an error if and only if Watcher cannot recover. 56 | Next() ([]*Update, error) 57 | // Close closes the Watcher. 58 | Close() 59 | } 60 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/peer/peer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package peer defines various peer information associated with RPCs and 20 | // corresponding utils. 21 | package peer 22 | 23 | import ( 24 | "net" 25 | 26 | "golang.org/x/net/context" 27 | "google.golang.org/grpc/credentials" 28 | ) 29 | 30 | // Peer contains the information of the peer for an RPC, such as the address 31 | // and authentication information. 32 | type Peer struct { 33 | // Addr is the peer address. 34 | Addr net.Addr 35 | // AuthInfo is the authentication information of the transport. 36 | // It is nil if there is no transport security being used. 37 | AuthInfo credentials.AuthInfo 38 | } 39 | 40 | type peerKey struct{} 41 | 42 | // NewContext creates a new context with peer information attached. 43 | func NewContext(ctx context.Context, p *Peer) context.Context { 44 | return context.WithValue(ctx, peerKey{}, p) 45 | } 46 | 47 | // FromContext returns the peer information in ctx if it exists. 48 | func FromContext(ctx context.Context) (p *Peer, ok bool) { 49 | p, ok = ctx.Value(peerKey{}).(*Peer) 50 | return 51 | } 52 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/pickfirst.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "golang.org/x/net/context" 23 | "google.golang.org/grpc/balancer" 24 | "google.golang.org/grpc/connectivity" 25 | "google.golang.org/grpc/grpclog" 26 | "google.golang.org/grpc/resolver" 27 | ) 28 | 29 | // PickFirstBalancerName is the name of the pick_first balancer. 30 | const PickFirstBalancerName = "pick_first" 31 | 32 | func newPickfirstBuilder() balancer.Builder { 33 | return &pickfirstBuilder{} 34 | } 35 | 36 | type pickfirstBuilder struct{} 37 | 38 | func (*pickfirstBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { 39 | return &pickfirstBalancer{cc: cc} 40 | } 41 | 42 | func (*pickfirstBuilder) Name() string { 43 | return PickFirstBalancerName 44 | } 45 | 46 | type pickfirstBalancer struct { 47 | cc balancer.ClientConn 48 | sc balancer.SubConn 49 | } 50 | 51 | func (b *pickfirstBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) { 52 | if err != nil { 53 | grpclog.Infof("pickfirstBalancer: HandleResolvedAddrs called with error %v", err) 54 | return 55 | } 56 | if b.sc == nil { 57 | b.sc, err = b.cc.NewSubConn(addrs, balancer.NewSubConnOptions{}) 58 | if err != nil { 59 | grpclog.Errorf("pickfirstBalancer: failed to NewSubConn: %v", err) 60 | return 61 | } 62 | b.cc.UpdateBalancerState(connectivity.Idle, &picker{sc: b.sc}) 63 | b.sc.Connect() 64 | } else { 65 | b.sc.UpdateAddresses(addrs) 66 | b.sc.Connect() 67 | } 68 | } 69 | 70 | func (b *pickfirstBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectivity.State) { 71 | grpclog.Infof("pickfirstBalancer: HandleSubConnStateChange: %p, %v", sc, s) 72 | if b.sc != sc { 73 | grpclog.Infof("pickfirstBalancer: ignored state change because sc is not recognized") 74 | return 75 | } 76 | if s == connectivity.Shutdown { 77 | b.sc = nil 78 | return 79 | } 80 | 81 | switch s { 82 | case connectivity.Ready, connectivity.Idle: 83 | b.cc.UpdateBalancerState(s, &picker{sc: sc}) 84 | case connectivity.Connecting: 85 | b.cc.UpdateBalancerState(s, &picker{err: balancer.ErrNoSubConnAvailable}) 86 | case connectivity.TransientFailure: 87 | b.cc.UpdateBalancerState(s, &picker{err: balancer.ErrTransientFailure}) 88 | } 89 | } 90 | 91 | func (b *pickfirstBalancer) Close() { 92 | } 93 | 94 | type picker struct { 95 | err error 96 | sc balancer.SubConn 97 | } 98 | 99 | func (p *picker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { 100 | if p.err != nil { 101 | return nil, nil, p.err 102 | } 103 | return p.sc, nil, nil 104 | } 105 | 106 | func init() { 107 | balancer.Register(newPickfirstBuilder()) 108 | } 109 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/resolver/dns/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.6, !go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package dns 22 | 23 | import ( 24 | "net" 25 | 26 | "golang.org/x/net/context" 27 | ) 28 | 29 | var ( 30 | lookupHost = func(ctx context.Context, host string) ([]string, error) { return net.LookupHost(host) } 31 | lookupSRV = func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) { 32 | return net.LookupSRV(service, proto, name) 33 | } 34 | lookupTXT = func(ctx context.Context, name string) ([]string, error) { return net.LookupTXT(name) } 35 | ) 36 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/resolver/dns/go18.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package dns 22 | 23 | import "net" 24 | 25 | var ( 26 | lookupHost = net.DefaultResolver.LookupHost 27 | lookupSRV = net.DefaultResolver.LookupSRV 28 | lookupTXT = net.DefaultResolver.LookupTXT 29 | ) 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/resolver/passthrough/passthrough.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package passthrough implements a pass-through resolver. It sends the target 20 | // name without scheme back to gRPC as resolved address. 21 | package passthrough 22 | 23 | import "google.golang.org/grpc/resolver" 24 | 25 | const scheme = "passthrough" 26 | 27 | type passthroughBuilder struct{} 28 | 29 | func (*passthroughBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOption) (resolver.Resolver, error) { 30 | r := &passthroughResolver{ 31 | target: target, 32 | cc: cc, 33 | } 34 | r.start() 35 | return r, nil 36 | } 37 | 38 | func (*passthroughBuilder) Scheme() string { 39 | return scheme 40 | } 41 | 42 | type passthroughResolver struct { 43 | target resolver.Target 44 | cc resolver.ClientConn 45 | } 46 | 47 | func (r *passthroughResolver) start() { 48 | r.cc.NewAddress([]resolver.Address{{Addr: r.target.Endpoint}}) 49 | } 50 | 51 | func (*passthroughResolver) ResolveNow(o resolver.ResolveNowOption) {} 52 | 53 | func (*passthroughResolver) Close() {} 54 | 55 | func init() { 56 | resolver.Register(&passthroughBuilder{}) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/stats/handlers.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package stats 20 | 21 | import ( 22 | "net" 23 | 24 | "golang.org/x/net/context" 25 | ) 26 | 27 | // ConnTagInfo defines the relevant information needed by connection context tagger. 28 | type ConnTagInfo struct { 29 | // RemoteAddr is the remote address of the corresponding connection. 30 | RemoteAddr net.Addr 31 | // LocalAddr is the local address of the corresponding connection. 32 | LocalAddr net.Addr 33 | } 34 | 35 | // RPCTagInfo defines the relevant information needed by RPC context tagger. 36 | type RPCTagInfo struct { 37 | // FullMethodName is the RPC method in the format of /package.service/method. 38 | FullMethodName string 39 | // FailFast indicates if this RPC is failfast. 40 | // This field is only valid on client side, it's always false on server side. 41 | FailFast bool 42 | } 43 | 44 | // Handler defines the interface for the related stats handling (e.g., RPCs, connections). 45 | type Handler interface { 46 | // TagRPC can attach some information to the given context. 47 | // The context used for the rest lifetime of the RPC will be derived from 48 | // the returned context. 49 | TagRPC(context.Context, *RPCTagInfo) context.Context 50 | // HandleRPC processes the RPC stats. 51 | HandleRPC(context.Context, RPCStats) 52 | 53 | // TagConn can attach some information to the given context. 54 | // The returned context will be used for stats handling. 55 | // For conn stats handling, the context used in HandleConn for this 56 | // connection will be derived from the context returned. 57 | // For RPC stats handling, 58 | // - On server side, the context used in HandleRPC for all RPCs on this 59 | // connection will be derived from the context returned. 60 | // - On client side, the context is not derived from the context returned. 61 | TagConn(context.Context, *ConnTagInfo) context.Context 62 | // HandleConn processes the Conn stats. 63 | HandleConn(context.Context, ConnStats) 64 | } 65 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/tap/tap.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package tap defines the function handles which are executed on the transport 20 | // layer of gRPC-Go and related information. Everything here is EXPERIMENTAL. 21 | package tap 22 | 23 | import ( 24 | "golang.org/x/net/context" 25 | ) 26 | 27 | // Info defines the relevant information needed by the handles. 28 | type Info struct { 29 | // FullMethodName is the string of grpc method (in the format of 30 | // /package.service/method). 31 | FullMethodName string 32 | // TODO: More to be added. 33 | } 34 | 35 | // ServerInHandle defines the function which runs before a new stream is created 36 | // on the server side. If it returns a non-nil error, the stream will not be 37 | // created and a RST_STREAM will be sent back to the client with REFUSED_STREAM. 38 | // The client will receive an RPC error "code = Unavailable, desc = stream 39 | // terminated by RST_STREAM with error code: REFUSED_STREAM". 40 | // 41 | // It's intended to be used in situations where you don't want to waste the 42 | // resources to accept the new stream (e.g. rate-limiting). And the content of 43 | // the error will be ignored and won't be sent back to the client. For other 44 | // general usages, please use interceptors. 45 | // 46 | // Note that it is executed in the per-connection I/O goroutine(s) instead of 47 | // per-RPC goroutine. Therefore, users should NOT have any 48 | // blocking/time-consuming work in this handle. Otherwise all the RPCs would 49 | // slow down. Also, for the same reason, this handle won't be called 50 | // concurrently by gRPC. 51 | type ServerInHandle func(ctx context.Context, info *Info) (context.Context, error) 52 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/trace.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "bytes" 23 | "fmt" 24 | "io" 25 | "net" 26 | "strings" 27 | "time" 28 | 29 | "golang.org/x/net/trace" 30 | ) 31 | 32 | // EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package. 33 | // This should only be set before any RPCs are sent or received by this program. 34 | var EnableTracing bool 35 | 36 | // methodFamily returns the trace family for the given method. 37 | // It turns "/pkg.Service/GetFoo" into "pkg.Service". 38 | func methodFamily(m string) string { 39 | m = strings.TrimPrefix(m, "/") // remove leading slash 40 | if i := strings.Index(m, "/"); i >= 0 { 41 | m = m[:i] // remove everything from second slash 42 | } 43 | if i := strings.LastIndex(m, "."); i >= 0 { 44 | m = m[i+1:] // cut down to last dotted component 45 | } 46 | return m 47 | } 48 | 49 | // traceInfo contains tracing information for an RPC. 50 | type traceInfo struct { 51 | tr trace.Trace 52 | firstLine firstLine 53 | } 54 | 55 | // firstLine is the first line of an RPC trace. 56 | type firstLine struct { 57 | client bool // whether this is a client (outgoing) RPC 58 | remoteAddr net.Addr 59 | deadline time.Duration // may be zero 60 | } 61 | 62 | func (f *firstLine) String() string { 63 | var line bytes.Buffer 64 | io.WriteString(&line, "RPC: ") 65 | if f.client { 66 | io.WriteString(&line, "to") 67 | } else { 68 | io.WriteString(&line, "from") 69 | } 70 | fmt.Fprintf(&line, " %v deadline:", f.remoteAddr) 71 | if f.deadline != 0 { 72 | fmt.Fprint(&line, f.deadline) 73 | } else { 74 | io.WriteString(&line, "none") 75 | } 76 | return line.String() 77 | } 78 | 79 | const truncateSize = 100 80 | 81 | func truncate(x string, l int) string { 82 | if l > len(x) { 83 | return x 84 | } 85 | return x[:l] 86 | } 87 | 88 | // payload represents an RPC request or response payload. 89 | type payload struct { 90 | sent bool // whether this is an outgoing payload 91 | msg interface{} // e.g. a proto.Message 92 | // TODO(dsymonds): add stringifying info to codec, and limit how much we hold here? 93 | } 94 | 95 | func (p payload) String() string { 96 | if p.sent { 97 | return truncate(fmt.Sprintf("sent: %v", p.msg), truncateSize) 98 | } 99 | return truncate(fmt.Sprintf("recv: %v", p.msg), truncateSize) 100 | } 101 | 102 | type fmtStringer struct { 103 | format string 104 | a []interface{} 105 | } 106 | 107 | func (f *fmtStringer) String() string { 108 | return fmt.Sprintf(f.format, f.a...) 109 | } 110 | 111 | type stringer string 112 | 113 | func (s stringer) String() string { return string(s) } 114 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/go16.go: -------------------------------------------------------------------------------- 1 | // +build go1.6,!go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package transport 22 | 23 | import ( 24 | "net" 25 | "net/http" 26 | 27 | "google.golang.org/grpc/codes" 28 | 29 | "golang.org/x/net/context" 30 | ) 31 | 32 | // dialContext connects to the address on the named network. 33 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 34 | return (&net.Dialer{Cancel: ctx.Done()}).Dial(network, address) 35 | } 36 | 37 | // ContextErr converts the error from context package into a StreamError. 38 | func ContextErr(err error) StreamError { 39 | switch err { 40 | case context.DeadlineExceeded: 41 | return streamErrorf(codes.DeadlineExceeded, "%v", err) 42 | case context.Canceled: 43 | return streamErrorf(codes.Canceled, "%v", err) 44 | } 45 | return streamErrorf(codes.Internal, "Unexpected error from context packet: %v", err) 46 | } 47 | 48 | // contextFromRequest returns a background context. 49 | func contextFromRequest(r *http.Request) context.Context { 50 | return context.Background() 51 | } 52 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package transport 22 | 23 | import ( 24 | "context" 25 | "net" 26 | "net/http" 27 | 28 | "google.golang.org/grpc/codes" 29 | 30 | netctx "golang.org/x/net/context" 31 | ) 32 | 33 | // dialContext connects to the address on the named network. 34 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 35 | return (&net.Dialer{}).DialContext(ctx, network, address) 36 | } 37 | 38 | // ContextErr converts the error from context package into a StreamError. 39 | func ContextErr(err error) StreamError { 40 | switch err { 41 | case context.DeadlineExceeded, netctx.DeadlineExceeded: 42 | return streamErrorf(codes.DeadlineExceeded, "%v", err) 43 | case context.Canceled, netctx.Canceled: 44 | return streamErrorf(codes.Canceled, "%v", err) 45 | } 46 | return streamErrorf(codes.Internal, "Unexpected error from context packet: %v", err) 47 | } 48 | 49 | // contextFromRequest returns a context from the HTTP Request. 50 | func contextFromRequest(r *http.Request) context.Context { 51 | return r.Context() 52 | } 53 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/log.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // This file contains wrappers for grpclog functions. 20 | // The transport package only logs to verbose level 2 by default. 21 | 22 | package transport 23 | 24 | import "google.golang.org/grpc/grpclog" 25 | 26 | const logLevel = 2 27 | 28 | func infof(format string, args ...interface{}) { 29 | if grpclog.V(logLevel) { 30 | grpclog.Infof(format, args...) 31 | } 32 | } 33 | 34 | func warningf(format string, args ...interface{}) { 35 | if grpclog.V(logLevel) { 36 | grpclog.Warningf(format, args...) 37 | } 38 | } 39 | 40 | func errorf(format string, args ...interface{}) { 41 | if grpclog.V(logLevel) { 42 | grpclog.Errorf(format, args...) 43 | } 44 | } 45 | 46 | func fatalf(format string, args ...interface{}) { 47 | if grpclog.V(logLevel) { 48 | grpclog.Fatalf(format, args...) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/vet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex # Exit on error; debugging enabled. 4 | set -o pipefail # Fail a pipe if any sub-command fails. 5 | 6 | die() { 7 | echo "$@" >&2 8 | exit 1 9 | } 10 | 11 | PATH="$GOPATH/bin:$GOROOT/bin:$PATH" 12 | 13 | # Check proto in manual runs or cron runs. 14 | if [[ "$TRAVIS" != "true" || "$TRAVIS_EVENT_TYPE" = "cron" ]]; then 15 | check_proto="true" 16 | fi 17 | 18 | if [ "$1" = "-install" ]; then 19 | go get -d \ 20 | google.golang.org/grpc/... 21 | go get -u \ 22 | github.com/golang/lint/golint \ 23 | golang.org/x/tools/cmd/goimports \ 24 | honnef.co/go/tools/cmd/staticcheck \ 25 | github.com/client9/misspell/cmd/misspell \ 26 | github.com/golang/protobuf/protoc-gen-go 27 | if [[ "$check_proto" = "true" ]]; then 28 | if [[ "$TRAVIS" = "true" ]]; then 29 | PROTOBUF_VERSION=3.3.0 30 | PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip 31 | pushd /home/travis 32 | wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} 33 | unzip ${PROTOC_FILENAME} 34 | bin/protoc --version 35 | popd 36 | elif ! which protoc > /dev/null; then 37 | die "Please install protoc into your path" 38 | fi 39 | fi 40 | exit 0 41 | elif [[ "$#" -ne 0 ]]; then 42 | die "Unknown argument(s): $*" 43 | fi 44 | 45 | # TODO: Remove this check and the mangling below once "context" is imported 46 | # directly. 47 | if git status --porcelain | read; then 48 | die "Uncommitted or untracked files found; commit changes first" 49 | fi 50 | 51 | git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | tee /dev/stderr | (! read) 52 | gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read) 53 | goimports -l . 2>&1 | tee /dev/stderr | (! read) 54 | golint ./... 2>&1 | (grep -vE "(_mock|\.pb)\.go:" || true) | tee /dev/stderr | (! read) 55 | 56 | # Undo any edits made by this script. 57 | cleanup() { 58 | git reset --hard HEAD 59 | } 60 | trap cleanup EXIT 61 | 62 | # Rewrite golang.org/x/net/context -> context imports (see grpc/grpc-go#1484). 63 | # TODO: Remove this mangling once "context" is imported directly (grpc/grpc-go#711). 64 | git ls-files "*.go" | xargs sed -i 's:"golang.org/x/net/context":"context":' 65 | set +o pipefail 66 | # TODO: Stop filtering pb.go files once golang/protobuf#214 is fixed. 67 | go tool vet -all . 2>&1 | grep -vE '(clientconn|transport\/transport_test).go:.*cancel (function|var)' | grep -vF '.pb.go:' | tee /dev/stderr | (! read) 68 | set -o pipefail 69 | git reset --hard HEAD 70 | 71 | if [[ "$check_proto" = "true" ]]; then 72 | PATH="/home/travis/bin:$PATH" make proto && \ 73 | git status --porcelain 2>&1 | (! read) || \ 74 | (git status; git --no-pager diff; exit 1) 75 | fi 76 | 77 | # TODO(menghanl): fix errors in transport_test. 78 | staticcheck -ignore ' 79 | google.golang.org/grpc/transport/transport_test.go:SA2002 80 | google.golang.org/grpc/benchmark/benchmain/main.go:SA1019 81 | google.golang.org/grpc/stats/stats_test.go:SA1019 82 | google.golang.org/grpc/test/end2end_test.go:SA1019 83 | ' ./... 84 | misspell -error . 85 | --------------------------------------------------------------------------------