nginx 实现首页不缓存 前端上 CDN 加速, 后端上 DCDN, 加速网站访问速度。 前端代码编译的时候, 可以加上 hash 值使编译后的产物名字随机, 可以在不刷新 CDN 资源 的情况下, 保障页面展示最新。 虽然对多了一点回源, 但减少了人工操作。 但是 首页不能被缓存, 否则于事无补。 对于首页的缓存设置, 有一点注意事项, 其一 ,……
阅读全文
如果在国内使用docker, 大家一般会配置各种加速器, 我一般会配置阿里云或腾讯云,还算比较稳定。 /etc/docker/daemon.json 配置如下 1 2 3 4 5 6 7 8 { "registry-mirrors": [ "https://mirror.ccs.tencentyun.com", "https://wlzfs4t4.mirror.aliyuncs.com" ], "bip": "169.253.32.1/24", "data-root": "/data/docker/var/lib/docker" } 上述配置, 对 docker.io 的镜像加速效果很好, 但对 google 镜像的加速效果就很差了比如k8s相关的以gcr.io或quay.io开头的镜像地址。 这个时候可以……
阅读全文
v2ray 配置 命令行快捷键 pxy='http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890 $@' client.json 同时监听 socks5 和 http 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 { "log": { "error": "", "loglevel": "info", "access": "" }, "inbounds": [ { "listen": "127.0.0.1", "protocol": "socks", "settings": { "udp": false, "auth": "noauth"……
阅读全文
typescript 将 json 序列化为 querystring 格式 使用 typescript 时, 需要同时安装 @types/qs 和 qs 1 yarn add @types/qs qs demo 1 2 3 4 5 6 7 8 9 const params = qs.stringify({ namespace: namespace, replicas: replicas, }) const u = `/deployments/${name}/replicas?${params}` console.log("Uuuuu::::", u); // Uuuuu:::: /deployments/failed-nginx/replicas?namespace=default&replicas=3……
阅读全文
使用 @ 路径别名 在使用 import 的时候, 可以使用相对路径 ../components/HelloWorld.vue 指定文件位置, 但这依赖文件本身的位置,在 跨目录 的时候, 并不方便。 例如, 路由文件 要使用 Components 组件 1 2 3 4 // file: /src/router/index.ts // 路由目标组件 import HelloWorld from '../components/HelloWorld.vue' import World from '../components/World.vue' 要使用路径别名, 需要进行一些额外配置 安装 @types/node 支持 安装 @types/node 组件 1 yarn add @types/node 在 tsconfig.json 中, compilerOptions 下配置 1 2 3 4 5 6 7 8 9……
阅读全文
安装 vue-router 路由支持 在 vue3 中使用的是 vue-router@next 版本 ^4.y.z 1 yarn add vue-router@next /src/router/index.ts 创建路由规则 安装之后, 在创建文件 /src/router/index.ts 作为 vue-router 的初始化文件。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // 导入创建路由所需的组件 import { createRouter, createWebHistory } from "vue-router"; // 路由目标组件 import HelloWorld from '../components/HelloWorld.vue' import World from '../components/World.vue' // 路由表 const routes = [ { path: "/helloworld", name: "HelloWorld", component: HelloWorld }, { path: "/world", name: "World", component: World } ] // 创……
阅读全文
gin 内部重定向时 middleware 不可用异常 axios 请求时出现 cors error 在使用 axios 请求后端时,遇到 cors 跨域问题, 虽然已经在 gin 中添加了 cors 的 middleware 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 func cors() gin.HandlerFunc { return func(c *gin.Context) { method := c.Request.Method origin := "*" if method != "" { c.Header("Access-Control-Allow-Origin", origin) // 可将将 * 替换为指定的域名 c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization,X-Token") c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type") c.Header("Access-Control-Allow-Credentials", "true") } if method == "OPTIONS" { c.AbortWithStatus(http.StatusNoContent) } } } 问题原因 gin Middleware……
阅读全文
K8S 使用 TTL 控制器自动清理完成的 Job Pod 最近为集群 CI 默认添加了 .spec.ttlSecondsAfterFinished 参数, 以便在 cronjob 和 job 运行完成后自动清理过期 pod 。 但是在 CI 的时候却失败, 报错如下。 1 spec.jobTemplate.spec.ttlSecondsAfterFinished: Forbidden: disabled by feature-gate 核查资料得知, 在 v1.21 之前, 该开关默认是关闭的。 刚好错误集群低于此版本。 Job TTL 控制器 K8S 提供了一个 TTL 控制器, 可以自动在 JOB Complete 或 Failed 之后, 经过一定时间……
阅读全文
太久没写, 都忘记了 golang slice 切片的完整表达式 原文链接: https://tangx.in/posts/2021/09/22/golang-slice-expressions/ 通常,我们写的 golang slice 边界只有两个数字 slice[1:3] , 这是一种简单写法。 而完整写法是 三个数字 slice[1:3:5] 简单表达式 一个冒号, 两个参数, 表示 slice 元素的 起止区间 1 a[low:high] 案例代码如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 package main import ( "fmt" ) func main() { a := [5]int{1, 2, 3, 4, 5} s := a[1:4] // [2,3,4] fmt.Println(s) s1 :=……
阅读全文
经过99次失败后, 我总结了几点 Golang 反射的经验(附源码) golang 反射很好用, 也有很多坑。 代码在: https://github.com/tangx-labs/golang-reflect-demo Kind 和 Type 在 golang 的反射中, 有两个可以表示 类型 的关键字, Kind 和 Type 。 定义覆盖范围 Kind 的定义覆盖范围比 Type 要大。 Kind 在定义上要 更抽象, Type 要更具体。 可以简单理解为, 如果 Kind 是 车 , 那么 Type 可能是 公交车 、 消防车 内置类型字面……
阅读全文