All of the following information is based on go version go1.17.1 darwin/amd64.
| GOOS | Out of the Box |
|---|---|
aix |
✅ |
android |
✅ |
| # 概述:一共三大部分配置。 | |
| # 其中#注释掉的可以在需要的时候开启并修改,没有注释掉的(除了下面location示例)不要删掉,基本都是必须的配置项。 | |
| ###############################第一部分 全局配置############################ | |
| #user nobody; 指定启动进程的用户,默认不用指定即可。 | |
| #error_log logs/error.log; 配置日志输出,虽然叫error_log但是可以定义输出的级别,默认不写是ERROR级别 | |
| #error_log logs/error.log notice; | |
| #error_log logs/error.log info; | |
| #pid logs/nginx.pid; 记录pid的文件,默认就是放到这个位置,可以修改。 |
| -- 直接赋值是全局变量一般不要这么使用 | |
| a = 10 | |
| -- local是指定当前作用域(一般指大括号或当前文件内)有效的变量 | |
| local a = 10 | |
| -- 数字 | |
| local b = 10.1 | |
| print(a + b) -- 打印20.1,支持常见的运算符以及位运算符 | |
| print(15 & (1<<2)) -- 4 |
| package xxx | |
| import ( | |
| "fmt" | |
| "io" | |
| "os" | |
| "strings" | |
| "sync" | |
| "testing" | |
| ) |
| <?php | |
| /** | |
| * getRandomWeightedElement() | |
| * Utility function for getting random values with weighting. | |
| * Pass in an associative array, such as array('A'=>5, 'B'=>45, 'C'=>50) | |
| * An array like this means that "A" has a 5% chance of being selected, "B" 45%, and "C" 50%. | |
| * The return value is the array key, A, B, or C in this case. Note that the values assigned | |
| * do not have to be percentages. The values are simply relative to each other. If one value | |
| * weight was 2, and the other weight of 1, the value with the weight of 2 has about a 66% | |
| * chance of being selected. Also note that weights should be integers. |
I needed to quickly encode a protobuf from the command-line, and while I pretty much immediately came across protoc --encode as the obvious solution, I did not find much documentation on the input textual syntax.
Here is the relevant snippet from protoc --help:
--encode=MESSAGE_TYPE Read a text-format message of the given type
from standard input and write it in binary
to standard output. The message type must
be defined in PROTO_FILES or their imports.
| // Package deepcopy provides a function for deep copying map[string]interface{} | |
| // values. Inspired by the StackOverflow answer at: | |
| // http://stackoverflow.com/a/28579297/1366283 | |
| // | |
| // Uses the golang.org/pkg/encoding/gob package to do this and therefore has the | |
| // same caveats. | |
| // See: https://blog.golang.org/gobs-of-data | |
| // See: https://golang.org/pkg/encoding/gob/ | |
| package deepcopy |
| /* | |
| * | |
| * Copyright 2018 gRPC authors. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * |
| /* | |
| * | |
| * Copyright 2018 gRPC authors. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * |
| package main | |
| import ( | |
| "errors" | |
| "fmt" | |
| "math/rand" | |
| "net/http" | |
| "sync" | |
| "time" |