beancount-gs 一款 self-hosted 复式记账程序,简化你的记账方式!

本程序将部署在 macOS 上,不使用 Docker(mac 上的 Docker 太卡了)

动机

我利用 beancount 来记账已经有一段时间了,但有些痛点问题困扰着我:

  • 没有 web 界面,fava 真的只能用来展示和分析且不好理解,需要有一个方便记账的界面
  • text 记账的方式,在 vscode 插件能力有限的情况下,很容易忘记 assets 和 expenses 到底叫啥名,如果有 web 界面那么一定会好很多,一个下拉列表就可以解决

有没有解决方案,不需要自己造轮子的那种?

  • 有!beancoutn-gs ,最近还在更新,就喜欢长期维护的!

主旨

下载与编译

我手头就一台 intel 的 MBP,不想装虚拟机,也绝不会想用 Docker Desktop(用过的都知道有多么卡和费电)。

因此,我的需求就是将程序作为服务直接在 mac 上跑,这不跟 Linux 的服务一个样么,多好啊。

bash
pip3 install beancount

git clone https://github.com/BaoXuebin/beancount-gs.git

beancount-gs

go build

完事,golang 就是好用啊!

我对源码中的监听端口做了修改,同时注释掉了打开浏览器的操作:

Untitled

还加入了环境变量的设置,防止找不到我的 beancount:

Untitled

请将编译好的可执行文件放到 /opt/beancount-gs/ 文件夹中。

还有很重要的事情是,把源码中编译好的前端文件夹 public 、 config 和 template 也 copy 到 /opt/beancount-gs/ 文件夹中,不然访问时啥也没有。

Untitled

开机自启动

launchd 是 macOS 内核装载后启动的第一个进程,类似 Linux 的1号进程。

Linux 中咱们是编写服务,然后使用 systemctl enable xxx 实现的。

编写 plist 文件

Plist 的全称是 Property lists 。

Untitled

类似的,macOS 就需要编写 plist 文件,放到用户登录后的 ~/Library/LaunchAgents 中:

xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>beancount-gs</string>
        <key>ProgramArguments</key>
        <array>
            <string>/opt/beancount-gs/beancount-gs</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>/opt/beancount-gs/</string>
        <key>StandardOutPath</key>
        <string>/opt/beancount-gs/beancount-gs.log</string>
        <key>StandardErrorPath</key>
        <string>/opt/beancount-gs/beancount-gs.log</string>
    </dict>
</plist>

这个就不用解释了吧,xml 文件就是写了一些键值对配置和启动的命令~

载入 plist 文件

man launchctl 查看用法吧

bash
launchctl load -w /Users/yuhanliu/Library/LaunchAgents/beancount-gs.plist
# launchctl unload -w /Users/yuhanliu/Library/LaunchAgents/beancount-gs.plist
# launchctl bootstrap user/501 ~/Library/LaunchAgents/beancount-gs.plist
# id -u yuhanliu 

launchctl start beancount-gs
# launchctl stop beancount-gs

Untitled

访问

Untitled

中间居然出现好多问题,这个程序的健壮性不是很强啊:

Untitled

我还要手动新建文件夹和对应的文件……

Untitled

参考文章

前言 · 语雀

Mac 开机自启动

comments powered by Disqus
相关文章
四则运算表达式求值:中缀改后缀

简介 在提到栈的应用时,有一个很典型的例子就是表达式求值。 具体应用时体现在: 中缀表达式转后缀表达式:运算符栈 后缀表达式求值:操作数栈 若直接进行中缀表达式求值,需同时操作两个栈,而将中缀表达式转为后缀表达式再求值时,每个步骤只需要专注于一个栈,操作起来更简单。本文就介绍这种方法。

阅读更多
用 Beancount 复式记账,Double-Entry!

🤔动机 已经有很多次记账的尝试,包括各种 App 如圈子账本(现已倒闭下架)等。但有几个痛点还没法解决: 大多数都是简单的记载收支,这对手握多个银行账户、信用卡等的我来说,显得不够用 数据安全问题,数据在服务提供者手上,既有隐私担忧,又受制于人,谁知道什么时候就删库跑路了 数据报表,大多数 App 的统计都比较垃,甚至需要 VIP 才能看

阅读更多
GORM 自动填充 UUID 的 2 种方式

使用 uuid 库手动生成 采用这个库:github.com/gofrs/uuid 在 GORM 中定义一个 BaseModel,并增加钩子函数: go 复制 已复制! import "github.com/gofrs/uuid" type BaseModel struct { ID uuid.UUID CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` EffectiveTime *time.Time } func (m *BaseModel) BeforeCreate() (err error) { m.ID, err = uuid.NewV4() if err != nil { log.Logger.Err(err).Msg("uuid create failed") return fmt.Errorf("uuid create with ID failed, %w", err) } return nil } 使用 postgresql 的 uuid-ossp 插件 首先要启用插件

阅读更多