serversideup VPS-Benchmarks-for-Self-hosters
https://521dimensions.notion.site/VPS-Benchmarks-for-Self-hosters-c6eca7c5f16d4bb8aeb989174fc58ffe
Hetzner Cloud
prohosting24 https://prohosting24.net/genoa 這間評價可,高防、效能不錯,無限流量,但用太多會限流,或是被踢掉,不能有法
Unmarshal dynamic JSON based on a type key
https://play.golang.com/p/BPWVd0WAfqR
package main
import (
"encoding/json"
"fmt"
)
var bodyA = []byte(`{
"type": "A",
"data": { "name": "Johnny" }
}`)
var bodyB = []byte(`{
"type": "B",
"data": { "nickname": "J." }
}`)
type TypeA struct {
Name string `json:"name"`
}
type TypeB struct {
Nickname string `json:"nickname"`
}
func main() {
req := struct {
Type string `json:"type"`
Data any `json:"data"`
}{}
err := json.Unmarshal(bodyA, &req) // bodyB
if err != nil {
panic(err)
}
switch req.Type {
case "A":
req.Data = new(TypeA)
case "B":
req.Data = new(TypeB)
}
err = json.Unmarshal(bodyA, &req) // bodyB
if err != nil {
panic(err)
}
message, _ := json.Marshal(&req)
fmt.Println(string(message))
}
訂閱:
文章 (Atom)