一篇文章告诉你 golang 环境变量的所有基础操作

一篇文章告诉你 golang 环境变量的所有基础操作 原文链接: https://tangx.in/posts/2021/09/06/golang-os-env-operation/ golang 中的环境变量操作都在 os 包下面, 只有很少的几个方法, 而且字面意思也很明确。 所有环境变量操作对象都是 字符串string , 因此对于 int, bool 类型需要自己实现转换。 golang 程序执行的时候, 是在 linux 系统中 fork 的一种子进程中 golang程序 在 复制了开……

阅读全文

typora 定义 github pages 专属配置

typora , 可以说一款为 github pages 网站量身定制的软件 配置初始目录 在 配置中 选择 General , 选择默认打开的目录。 配置图片路径 众所周知, Github Pages(Jekyll) 中, 文章需要放到 _post 下, 而资源应该另外创建目录, 如 assert 等。 这就造成了普通 markdown 编辑器插入图片的不方便。 解决方法如下: 使用图床, 彻底外部独立, 不存在相对路径的问题 放在 assert 下面, 但本……

阅读全文

typescript vue3 项目容器化实战

typescript vue3 项目容器化实战 在前端容器化的时候, 有一个绕不开的问题: 容器返回的后端地址应该怎么设置。 静态编译到所有文件中, 肯定是不可取的, 总不能后端变更一个访问域名,前端都要重新构建一次镜像吧? 由于 js (typescript 编译后 ) 实际是运行在 用户的浏览器上, 所以也不能像后端一样读取环境变量。 所以, 通过 html <meta> 标签……

阅读全文

typescript 中使用 @ 路径别名

typescript 中使用 @ 路径别名 使用路径别名 @/some/path/index.ts 可以很简单的表示一个文件的绝对路径(其实是相对于 @ 的相对路径) 安装 @types/node 1 yarn add @types/node 配置 tsconfig.json , 一下是基于 vite2 项目配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "compilerOptions": { // ... , "types": [ "node" ], // https://github.com/vitejs/vite/issues/279 "paths": { "@/*": [ "./src/*", ] } }, // ... } 就可以在 ts 文件中使用 @ 别名引入了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17……

阅读全文

vue3 使用 vite2 初始化项目

vue3 使用 vite2 初始化项目 vue3 + vite2 + typescript 配置 使用 vite2 创建项目 1 2 3 4 5 6 # 交换式 yarn create vite # 非交互式 yarn create vite project-name --template vue-ts 创建项目之后, cd project-name 进入项目, 是用 yarn 安装依赖, 使用 yarn dev 运行程序。 安装 less 支持 less 是 css 的一个超集。 yarn add less 安装之后, 可以在 CompName.vue 中使用 less 语法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // CompName.vue <template> <div class="div1"> <h3>div1</h3> <div class="div2"> <h3>div2</h3> </div> </div> </template>……

阅读全文

一道 golang 切片面试题

一道 golang 切片面试题 为什么 sl[:5] 会返回底层数组的数据呢? 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 package main import "fmt" func main() { sl := make([]int, 0, 10) appendFn := func(s []int) { // 值传递, s 并不是 sl。 // 但数组是引用类型, 所以可以修改底层数组 fmt.Println("s ptr(old):", s) // [] s = append(s, 10, 20, 30) fmt.Println("s ptr(new):", s) // [10,20,30] } fmt.Println(sl) // [] appendFn(sl) fmt.Println(sl) // [] // 这里有点坑, 并不是取的 sl ,而是底……

阅读全文

golang 下划线完成对象的接口类型检查

golang 下划线完成对象的接口类型检查 在 Gin 源码中 有一行代码如下 1 var _ IRouter = &RouterGroup{} 乍一看, 是一个 赋值 操作, 但是前面又使用了 空白描述符(下划线) 。 这是什么意思呢? 答案是: 接口类型检查 在 《Effective GO》 Interface Check 中的描述有相关描述。 全文如下。 One place this situation arises is when it is necessary to guarantee within the package implementing the type that it actually satisfies the interface. If a type-for……

阅读全文

typescript 中的 const 断言

typescript 中的 const assertions const assertions - TypeScript 3.4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // vue3 const dnsProviders = { "aliyun.com": "alidns", "tencent.com": "dnspod" } let data = reactive({ rootDomain: "aliyun.com" as const }) let dnsProvider = computed( () => { return dnsProviders[data.rootDomain] } ) 这个时候会, 提示 7053 错误, data.rootDomain 具有 any type, 不能被用作 key。 解决这个问题使用, 需要使用 typescript 中 const assertion 类型推断。 const assertion 类型推断。 字面量类型推断: 其类型为字面值类型。 例如这里的 hello 的类型是……

阅读全文

typescript 中的时间处理

typescript 中的时间处理 在 typescript/ javasctipt 中, 时间 是一个 构造 函数, 需要通过 const dt = new Date(xxx) 进行初始化创建时间对象。 创建时间对象 1 2 3 4 5 6 7 8 9 10 // 获取当前时间对象 const now = new Date() // 将字符串时间转换为 Date 时间对象 const timeStr = '2021-08-23T02:42:17Z' const dt = new Date(timeStr) // 根据数字创建时间 const dt2 = new Date(Date.UTC(2006, 0, 2, 15, 4, 5)); console.log("event:::", dt2); 时间操作 获取时间对象的属性值 通过 getXXX() 方法, 可以……

阅读全文

golang 中的时间处理

golang 中的时间处理 在 golang 中有一个很重要的 格式化时间的字符串 2006-01-02T15:04:05Z07:00 , 这个也是 golang 默认时间模版模版中的 time.RFC3339 1 RFC3339 = "2006-01-02T15:04:05Z07:00" golang 中关于时间的处理, 用到了上面的 每一个 数字和字母。 需要特别注意的是, 时区用的是 7 而非 6 , 因为 6 已经在 年(2006) 中出现了 创建时间对象 time.Time 1 2 3 4 5 6 7 8 9 10 // 1. 创建当前时间对象 now := time.Now() //……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它