2024-10-18

📝紀錄:Go 語言一些我常需要用到的資訊

Go 各版本的 Windows 支援程度

參閱官方Wiki:《Go for Microsoft Windows

安裝多版本的 Go

參閱官方說明:«Download and install»

首先先執行以下指令

go install golang.org/dl/go{你要的版本}@latest

然後再執行

go{你要的版本}} download

列出所有支援操作系統及架構

指令:

go tool dist list
輸出結果
js/wasm
linux/386
linux/amd64
linux/arm
windows/386
windows/amd64
windows/arm
windows/arm64

可以在後面加上-json 以 JSON格式輸出

加上-json後的輸出結果
[
        {
                "GOOS": "linux",
                "GOARCH": "386",
                "CgoSupported": true,
                "FirstClass": true
        },
        {
                "GOOS": "linux",
                "GOARCH": "amd64",
                "CgoSupported": true,
                "FirstClass": true
        },
        {
                "GOOS": "linux",
                "GOARCH": "arm",
                "CgoSupported": true,
                "FirstClass": true
        },
        
        // 下略……
]

參考自:impluse:《go列出所有支持的系统平台及其架构》

跨平台編譯

參閱官方Wiki:«Building Windows Go programs on Linux»

先設置變數

C:> set GOOS=windows 
C:> set GOARCH=386

然後進行 go build 指令。

如果是 linux 則是

$ GOOS=windows 
$ GOARCH=386
$ go build .

不過 linux 可以簡化成

$ GOOS=windows GOARCH=386 go build .

2024-09-11

做 Hibernate envers 設定時遇到的坑

這篇算是延續先前《SpringBoot 使用多個資料庫連線》的狀況

我今天想要使用Hibernate envers來處理資料的版控。

原先我是這樣處理的:

  1. pom.xml 加上library

    <dependency>
    	<groupId>org.hibernate</groupId>
    	<artifactId>hibernate-envers</artifactId>
    </dependency>
  2. application.properties 加上設定

    spring.jpa.properties.hibernate.envers.audit_table_suffix=_rev
    spring.jpa.properties.hibernate.envers.revision_field_name=rev
    spring.jpa.properties.hibernate.envers.revision_type_field_name=revtype
    
  3. Hibernate Entity 加上 @Audit
    import javax.persistence.Entity;
    import javax.persistence.Table;
    
    import org.hibernate.envers.Audited;
    
    @Entity
    @Audit
    @Table(name = "my_entity")
    class MyEntity{
    	// 中略
    }

然而,實際執行時,Hibernate 處理版控資料時,都想要存入 my_entity_AUD,即

insert into `my_entity_AUD` 
# 下略

2024-08-16

以數字開頭的 class element

如果 HTML code 如下

<span>Hello</span>&nbsp;
<span class="123">John Smith</span>

而 CSS 寫成如下,是無法作用的

.123{
	font-weight: bold;
	color: CornflowerBlue;
}

2024-08-12

Logback 設定

最近在調整自己開發的系統的 log。程式使用 Spring Boot,log 使用 logback。

我的目的是要讓其 log 到一定量就自動壓縮成 .gz檔、每天壓縮。

2024-07-19

OAuth 2.0 的 PKCE 筆記

PKCE 詳細規格請參閱 RFC7636

我在撰寫 OAuth 2.0 的登入時,會遇到 code_verifiercode_challenge 一直對不起來的狀況。

舉例來說,我請求 token 的參數為

client_id=aaa&
client_secret=bbb&
code=thisisasimpletoken&
code_verifier=HelloWorld&
grant_type=authorization_code

按照規範,我取得 authorization code 的 request 應該是 

client_id=aaa&
response_type=code&
scope=User.Read.All&
response_mode=form_post&
code_challenge_method=S256&
code_challenge=<將“HelloWorld”以 S256 加密後的字串>

2024-06-07

SVG 文字置中

首先是個普通的 SVG:

Hi! quick fox
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 200" width="300">
	<g fill="none" stroke="rgba(22, 22, 22, 0.5)">
		<path d="M 90 90 L 110 110 Z"/>
		<path d="M 110 90 L 90 110 Z"/>
	</g>
	<text font-family="Arial, sans-serif" x="100" y="100" font-size="30">Hi! quick fox</text>
</svg>

為了方便辨識,在 (100, 100) 的位置打了個叉。



上面的 SVG 可以看出來,文字無論是 x 軸還是 y 軸都沒有置中。