V2EX POST
648 subscribers
138 photos
31 videos
99 files
104K links
v2ex新贴定时推送,可按需置顶本频道然后关闭通知
Download Telegram
对 TypeScript 的类型系统越来越感兴趣,听说了一个名字叫作「类型体操」,有 v 友可以指点一下吗?大家也可以讨论一下。

旧的语言还未远去,新的语言不断涌现,我不能落下太远,那就从 TypeScript 开始吧,后面还有 Rust ,Ruby ,Erlang ,Lisp 。

#语言 #TypeScript #Rust #Ruby #Erlang #Lisp #不断涌现 #远去 #太远 #落下
分享一下最近新写的 Web API 框架

在这个主题下发布应该没错吧。

零零总总写了有半年了,虽然现在并不是一个发布的好时机,但是想要先分享出来和大家伙交流一下想法。本来打算先在公司用起来的,不过最近公司没有什么新项目,老项目我也不想换框架了,人力物力呀…… 所以只在自己的个人项目下应用了,目前运转良好。

又是一个轮子,只不过有些不一样的地方。

首先,思想上它是完全面向 API 文档的。也许好多团队写文档会借助于 YAPI 这样的第三方工具,或者直接用 Postman 这样用用例来说话,再不济手写 Markdown. 我在框架里直接生成了 OpenAPI 的规格文档,在开发者实现接口的同时,文档就生成了。例如像下面这样定义一个接口,同时文档就能生成了:

```ruby
route('/users', :post)
.title('创建一个新用户')
.params {
param :user, type: 'object', using: UserEntity
}
.do_any {
# 这里实现你的业务逻辑 ...
}
.if_status(201) {
expose :user, type: 'object', using: UserEntity
}
```

其次,这次将参数和返回值的写法统一起来了。像上面,我们只用了一个 `UserEntity`,就可以同时定义参数和返回值了,再也不用写两遍了。你的 `UserEntity` 内部可能是这样写的:

```ruby
class UserEntity
property :id, type: 'integer', param: false # 只返回
property :password, type: 'string', render: false # 只用作参数
property :name, type: 'string,
property :age, type: 'integer'
end
```

其他的功能还有很多,就不想一一列举了。想进一步了解的,可以去看 GitHub 仓库:

> https://github.com/yetrun/web-frame

这个框架适合纯 API 后端的场景,即前后端分离。也比较适合团队,基本用一种固定的写法构建 API. 重点是生成对应的文档,前后端不再扯皮(你的文档是这么定义的,怎么你返回的数据是长这样啊之类的云云)。

说实话最近整体的工作节奏都有些慢,受大环境的影响吧。本来打算等到我稳定运行后再发布了,但是这可能还要一阵子,就先预先发布一下看看反馈再说。现在大家运行起来可能有点吃力,因为还缺一个项目脚手架,后面会补上。

如果觉得对你有用,还望支持一下,对我回复个 +1. 如果大家热情足够的话,因为涉及到文档,我感觉上手难度还是有的,到时会建个 QQ 群或微信群做全面的答疑。如果大家热情不高,我就当成一个小众项目在我的团队里使用吧。视反馈而定。

#文档 #type #UserEntity #property #API #生成 #项目 #ruby #param #user
Golang/Rust 项目 工作流 - 你只需要构建一次

![banner]( https://res.cloudinary.com/practicaldev/image/fetch/s--YUU2aAli--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rtyy0zkidxjl0sceby9m.jpg)

## 起因

在猫盘上运行 cloudflared , 下载 cloudflared 的二进制,还想着有没有 arm 架构的 docker 镜像。
发现并没有,于是想着自己能制作一下。自己对 docker buildx 也会用了。

更古早的起因来自 mirr.one 镜像项目(现已停止),当时做了 caddy L4 的多架构镜像,来完成 git 协议的加速。

## 发现问题

二进制已经构建了一次, 而制作 docker 镜像还构建了一次。这不节能!

## 可行的方案

下载 github release 的二进制,使用它来构建 Docker 镜像。 问题在于有些架构可能没有构建并发布。

caddy 服务器有一个不错的二进制下载站点,胜在全面。但构建 Docker 镜像还需要下载这一步, 有 base 镜像层的存在。

## 优雅的实现

来自 docker buildx 提供的 ARG TARGETPLATFORM , 这是一个合法的 POSIX 路径名称。

如果我摆放合理, 我应该能把地球立在鸡蛋上。


下面是其中一个项目介绍: 具体实现请看超简单的源码。

## 特色

只要构建成功, 二进制就会被上传到 Artifacts, 没有一个 workflow 的努力被白白浪费。关爱纯纯牛马,关爱纯纯苦力。

另 Artifacts 可以 每一个文件生成单独条目,这是我 fork actions/upload-artifact 添加的特性,正等待上游合并. 预先体验可以参考 https://github.com/initdc/golang-project-workflow/blob/dev/.github/workflows/merge-pull-request.yml#L26

## 360 度旋体三周半 求 Star

- https://github.com/initdc/golang-project-workflow

- https://github.com/initdc/rust-project-workflow

之前写的博文

- https://dev.to/initd/golangrust-project-workflow-1592

---


# [Golang Project Workflow]( https://github.com/initdc/golang-project-workflow)

> Project written by go, you just need build once time.

## 在 Linux 主机上构建

1. 依赖

- go
- ruby
- tree
- sha256sum
- docker

2. 构建

> edit config and build CMD as you need
```
# 构建二进制
ruby build.rb
ruby build.rb --run-test
ruby build.rb v0.0.2
ruby build.rb less ## build bin for LESS_OS_ARCH
echo > version.rb 'VERSION = "fix-bug-001"'
ruby build.rb test --run-test

# 构建 Docker 镜像
ruby docker-tag.rb
ruby docker-tag.rb v0.0.2
ruby docker-tag.rb dev
ruby docker-tag.rb v$(TZ=Asia/Shanghai date +%Y.%m.%d)
```

## GitHub actions

- 构建二进制
- 上传到 release
- 构建 Docker 镜像并推送

## 更多关于 docker

查看 https://github.com/initdc/ssh-proxy-by-caddy-l4

## License

MPL 2.0

### #docker #ruby #rb #https #build #构建 #镜像 #com #github
Rust 是有什么黑魔法吗?每次用了就忘

之前用 Rust 写了个很简短的小项目,时隔一年多,又要捡起来用了,忘了个干净。。。然后翻着翻着突然想起来好像再往前一年也写过一个 Rust 的小项目。。。

Ruby ,Javascript ,Swift 都没有给我这种感觉,甚至 N 久前浅接触的 Elixir 都没有这种感觉,就 Rust 特别行,每次都忘个干净。。。

#Rust #干净 #Ruby #Javascript #Swift #久前 #Elixir #忘个 #感觉 #一年
Ruby on Mac

https://www.rubyonmac.dev/

解决 Ruby 开发环境在 macOS 上各种安装问题的方案。

#https #www #rubyonmac #dev #Ruby #macOS #安装 #方案 #开发 #解决
有捞人的吗?十五年 PHP +Ruby,会多种语言,有团队管理经验。

早期写 PHP ,自己撸框架,2014 年以后就转 Ruby 了。
老前端,上古时期还调试过 ie6 。资深 Linux 运维 07 年的 RHCE 。

各种语言基本也都玩过,不过没有实际工作项目给做,所以一直还是 Ruby on Rails 。
各种项目都做过,也带过挺多团队的,最多 30 人规模。

项目并发最高 1200 万 /天

现在疫情冲击下公司倒闭,本地经济不振。

求一线城市大佬捞人,可撸代码(前后端)、可运维。

V:RHJvZ29LaW5n

#Ruby #项目 #PHP #2014 #ie6 #Linux #运维 #07 #RHCE #Rails
Installing Jekyll on macOS Ventura

I have been following [this tutorial]( https://sboots.ca/2021/07/20/installing-jekyll-locally-on-macos-big-sur/) by Sean Boots on how to install Jekyll on previous versions of macOS. It worked really well and provided a smooth installation process. However, since the latest version of macOS (Ventura) still ships with Ruby 2.6, some Gems started to complain about that. So, I found a new method that uses the excellent [rbenv]( https://github.com/rbenv/rbenv) project to install a newer version of Ruby.

### 1. Install rbenv with Homebrew.

```
brew install rbenv ruby-build
```

Add this to `~/.zshrc` if you are using zsh:

```
eval "$(rbenv init - zsh)"
```

### 2. Change to your Jekyll blog's work directory, and install a newer version of Ruby:

```
rbenv install 3.1.3
```

### 3. Activate it for your Jekyll:

```
rbenv local 3.1.3
```

Check if you have got the desired version:

```
ruby -v
```

It should output something like this:

```
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]
```

If you see an older version like this:

```
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]
```

Check previous steps.

### 4. Install the two essential gems:

```
gem install bundler jekyll
```

### 5. Set bundle to use a local folder inside your website:

```
bundle config set --local path 'vendor/bundle'
```

### 6. Install the rest of gems:

```
bundle install
```

If you encounter any issues with any Gems, try deleting the Gemfile.lock and running the command again.

### 7. Exclude the vendor folder in your Jekyll config file, for example:

```
exclude:
- .ruby-gemset
- .ruby-version
- Gemfile
- Gemfile.lock
- Makefile
- README.md
- vendor/
```

You will also need to add the following lines into `.gitignore`:

```
vendor/
.bundle/
```

### 8. Your Jekyll installation is now set up and ready to use. To launch a live preview, try running the following command:

```
bundle exec jekyll serve --watch
```

---

I hope you are enjoying the ride. However, that is also part of the reason I started working on [Planetable.xyz]( https://planetable.xyz), a static site generator with a graphical interface and built-in IPFS node. With the Planet app, you don't need any command line knowledge to start blogging and self-hosting on your Mac.

#rbenv #### #install #version #ruby #bundle #Jekyll #your #vendor #following