Skip to content

Commit 81b07ec

Browse files
committed
change page of viper
1 parent c6da2ad commit 81b07ec

File tree

4 files changed

+279
-2
lines changed

4 files changed

+279
-2
lines changed

Arango/README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
docker启动:https://hub.docker.com/_/arangodb/
2+
```
3+
docker run -e ARANGO_RANDOM_ROOT_PASSWORD=1 -d arangodb
4+
//随机生成一个密码.默认用户名root,,docker logs 查看密码
5+
```
6+
7+
SQL|AQL
8+
---|---
9+
database | database
10+
table| collection
11+
row| document
12+
column| attribute
13+
table joins| collection joins
14+
primary key| _key
15+
index| index
16+
17+
场景|SQL|AQL
18+
----|---|---
19+
插入一条|INSERT INTO users (name, gender) VALUES ("John Doe", "m");|INSERT {name: "John Doe", gender: "m" } INTO users
20+
插入多条|INSERT INTO users (name, gender) VALUES ("John Doe", "m"),("Jane Smith", "f")|FOR user IN [{ name: "John Doe", gender: "m" }, { name: "Jane Smith", gender: "f" } ] INSERT user INTO users
21+
更新|UPDATE users SET name = "John Smith" WHERE id = 1;|UPDATE { _key:"1" } WITH { name: "John Smith" } IN users
22+
删除id|DELETE FROM users WHERE id = 1;|REMOVE { _key:"1" } IN users
23+
删除多个|DELETE FROM users WHERE active = 1|FOR user IN users FILTER user.active == 1 REMOVE user IN users
24+
查询|selct * from users | for u in users return u
25+
排序|SELECT * FROM users WHERE active = 1 ORDER BY name, gender| FOR user IN users FILTER user.active == 1 SORT user.name, user.gender RETURN user
26+
条数|SELECT gender, COUNT(*) AS number FROM users WHERE active = 1 GROUP BY gender|FOR user IN users FILTER user.active == 1 COLLECT gender = user.gender WITH COUNT INTO number RETURN { gender: gender, number: number }
27+
分组|SELECT YEAR(dateRegister) AS year, MONTH(dateRegister) AS month, COUNT(*) AS number FROM users WHERE active = 1 GROUP BY year, month HAVING number > 20;|FOR user IN users FILTER user.active == 1 COLLECT year = DATE_YEAR(user.dateRegistered), month = DATE_MONTH(user.dateRegistered) WITH COUNT INTO number FILTER number > 20 RETURN { year: year, month: month, number: number }
28+
最大值最小值|SELECT MIN(dateRegistered) AS minDate, MAX(dateRegistered) AS maxDate FROM users WHERE active = 1;|FOR user IN users FILTER user.active == 1 COLLECT AGGREGATE minDate = MIN(user.dateRegistered), maxDate = MAX(user.dateRegistered) RETURN { minDate, maxDate }
29+
join|SELECT * FROM users INNER JOIN friends ON (friends.user = users.id);|FOR user IN users FOR friend IN friends FILTER friend.user == user._key RETURN MERGE(user, friend)//合并
30+
left join|SELECT * FROM users LEFT JOIN friends ON (friends.user = users.id); |FOR user IN users LET friends = ( FOR friend IN friends FILTER friend.user == user._key RETURN friend ) FOR friendToJoin IN ( LENGTH(friends) > 0 ? friends : [ { /* no match exists */ } ] ) RETURN { user: user, friend: friend }
31+
32+
## graphs-->aql
33+
1.一种是找层级(几度好友)
34+
2.一种是找最近的路径
35+
1.语法:
36+
FOR vertex[, edge[, path]]
37+
IN [min[..max]]
38+
OUTBOUND|INBOUND|ANY startVertex
39+
GRAPH graphName
40+
[OPTIONS options]
41+
42+
vertex:点
43+
edge:线
44+
path:点和线组成(分:vertices和edges)
45+
min..max:从几度到第几度
46+
OUTBOUND|INBOUND|ANY:从某个顶点传出.传出或双向
47+
GRAPH graphName: graphs表名称
48+
49+
例如:查询某个用户1度好友关系
50+
```
51+
for v,e in 1 OUTBOUND @user_key GRAPH 'user_follow'
52+
filter e._to!=@user_key
53+
return v.user_id
54+
55+
```
56+
@user_key等以@开头的为占位符,防止注入
57+
```
58+
语法:@分割
59+
FOR u IN users
60+
FILTER u.id == @id && u.name == @name
61+
RETURN u
62+
api:
63+
{
64+
"query": "FOR u IN users FILTER u.id == @id && u.name == @name RETURN u",
65+
"bindVars": {
66+
"id": 123,
67+
"name": "John Smith"
68+
}
69+
}
70+
```
71+
72+
2.语法:
73+
FOR vertex[, edge]
74+
IN OUTBOUND|INBOUND|ANY SHORTEST_PATH
75+
startVertex TO targetVertex
76+
GRAPH graphName
77+
[OPTIONS options]
78+
例如:
79+
```
80+
FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A'
81+
TO 'circles/D'
82+
GRAPH 'traversalGraph'
83+
RETURN [v._key, e._key]
84+
85+
```
86+
87+
AQL:函数:https://docs.arangodb.com/3.2/AQL/Functions/
88+
Aql操作:https://docs.arangodb.com/3.2/AQL/Operations/

Caddy/README.md

100644100755
+40-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1-
#### project-readme
1+
```
2+
download: https://caddyserver.com/download
23
3-
遇到的问题和需要避免的一些错误的认知,提高自己的能力,我们在路上!
4+
caddy文件解压缩到/usr/bin目录
5+
6+
caddyfile的编写
7+
8+
sub.domainname.com {
9+
10+
max_certs 1 //证书最大数量
11+
}
12+
proxy / localhost:3000
13+
}
14+
更多语法参考
15+
https://caddyserver.com/docs/caddyfile
16+
17+
在caddyfile目录下运行caddy即可,或在任 意目录运行(ROOT身份),
18+
(目的:输入邮箱生成LETSENCRYPT证书,存放于ROOT根目录.caddy下)
19+
> caddy -conf /path/to/Caddyfile
20+
21+
caddy会下载证书,建立加密通道,并将请求转发至 3000
22+
23+
supervisor守护caddy
24+
25+
如果在caddy.log中出现需要输入邮箱的 prompt则在caddyfile中设定 `tls [email protected]`
26+
supervisorctl.stop caddy
27+
supervisorctl start caddy
28+
29+
> vim /etc/supervisord.d/caddy.ini
30+
or
31+
> vim /etc/supervisord.conf
32+
supervisor添加配置
33+
[program:caddy]
34+
command=caddy -conf ........./Caddyfile
35+
directory=/root/app/caddy
36+
environment=PWD=/root/app/caddy
37+
autostart=true
38+
autorestart=true
39+
stopsignal=KILL
40+
41+
```

Viper/0.1.md

+92
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,95 @@
11
#### project-readme
22

33
遇到的问题和需要避免的一些错误的认知,提高自己的能力,我们在路上!
4+
5+
6+
#### viper的使用
7+
8+
```go
9+
10+
package viper
11+
12+
import (
13+
"os"
14+
"path"
15+
"strings"
16+
17+
"github.com/spf13/cast"
18+
"github.com/spf13/viper"
19+
"github.com/sunmi-OS/gocore/utils"
20+
)
21+
22+
var C *viper.Viper
23+
24+
// 初始化配置文件
25+
// filePath 配置文件路径
26+
// fileName 配置文件名称(不需要文件后缀)
27+
func NewConfig(filePath string, fileName string) {
28+
29+
C = viper.New()
30+
C.WatchConfig()
31+
C.SetConfigName(fileName)
32+
//filePath支持相对路径和绝对路径 etc:"/a/b" "b" "./b"
33+
if (filePath[:1] != "/") {
34+
C.AddConfigPath(path.Join(utils.GetPath(), filePath))
35+
} else {
36+
C.AddConfigPath(filePath)
37+
}
38+
39+
// 找到并读取配置文件并且 处理错误读取配置文件
40+
if err := C.ReadInConfig(); err != nil {
41+
panic(err)
42+
}
43+
44+
}
45+
46+
47+
// 获取配置文件优先获取环境变量(返回string类型)
48+
func GetEnvConfig(key string) string {
49+
50+
// 转大写 . 转 _ 获取环境变量判断是否存在(存在直接返回,不存在使用viper配置)
51+
env := os.Getenv(strings.Replace(strings.ToUpper(key), ".", "_", -1))
52+
if env != "" {
53+
return env
54+
}
55+
56+
return C.GetString(key)
57+
}
58+
59+
// 获取配置文件优先获取环境变量(返回int类型)
60+
func GetEnvConfigInt(key string) int64 {
61+
62+
env := os.Getenv(strings.Replace(strings.ToUpper(key), ".", "_", -1))
63+
if env != "" {
64+
return cast.ToInt64(env)
65+
}
66+
67+
return C.GetInt64(key)
68+
}
69+
70+
// 获取配置文件优先获取环境变量(返回Float类型)
71+
func GetEnvConfigFloat(key string) float64 {
72+
73+
env := os.Getenv(strings.Replace(strings.ToUpper(key), ".", "_", -1))
74+
if env != "" {
75+
return cast.ToFloat64(env)
76+
}
77+
78+
return C.GetFloat64(key)
79+
}
80+
81+
// 获取配置文件优先获取环境变量(返回Bool类型)
82+
func GetEnvConfigBool(key string) bool {
83+
84+
env := os.Getenv(strings.Replace(strings.ToUpper(key), ".", "_", -1))
85+
if env != "" {
86+
return cast.ToBool(env)
87+
}
88+
89+
return C.GetBool(key)
90+
}
91+
92+
93+
94+
95+
```

Viper/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## 安装
2+
go get github.com/spf13/viper
3+
4+
## ECTD集成(GPG加密)
5+
6+
```
7+
$> go get github.com/xordataexchange/crypt
8+
$> go install github.com/xordataexchange/crypt/bin/crypt
9+
$> vim app.batch
10+
```
11+
12+
```
13+
%echo Generating a configuration OpenPGP key
14+
Key-Type: default
15+
Subkey-Type: default
16+
Name-Real: app
17+
Name-Comment: app configuration key
18+
Name-Email: [email protected]
19+
Expire-Date: 0
20+
%pubring .pubring.gpg
21+
%secring .secring.gpg
22+
%commit
23+
%echo done
24+
```
25+
26+
```
27+
$> gpg2 --batch --armor --gen-key app.batch
28+
$> crypt set -keyring .pubring.gpg /config/config.toml config.toml
29+
$> docker run -d -p 4001:4001 --name some-etcd elcolio/etcd:latest
30+
```
31+
32+
**go sample code**
33+
34+
```
35+
package main
36+
37+
import (
38+
"fmt"
39+
40+
"github.com/spf13/viper"
41+
_ "github.com/spf13/viper/remote"
42+
)
43+
44+
func main() {
45+
viper.AddSecureRemoteProvider("etcd","http://127.0.0.1:4001","/config/config.toml",".secring.gpg")
46+
viper.SetConfigType("toml")
47+
go func(){viper.WatchRemoteConfig()}()
48+
err := viper.ReadRemoteConfig()
49+
if err != nil {
50+
fmt.Println(err)
51+
return
52+
}
53+
fmt.Println(viper.GetString("postgres.port"))
54+
var w string
55+
fmt.Scanf("%s", &w)
56+
fmt.Println(w)
57+
fmt.Println(viper.GetString("postgres.port"))
58+
}
59+
```

0 commit comments

Comments
 (0)