V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  swordfairy  ›  全部回复第 3 页 / 共 7 页
回复总数  128
1  2  3  4  5  6  7  
280 天前
回复了 FakerLeung 创建的主题 iPhone iPhone 完全死机怎么办?
之前碰到过一次屏幕触摸没反应,还是在地铁口,还是让地铁安检小哥查的硬重启办法。 按一次音量+−,再长按开机键,等待硬重启。


如果经常遇到,建议重置系统试试,看能否解决
288 天前
回复了 smile561607154 创建的主题 Go 编程语言 有没有人来实现一下这个功能
288 天前
回复了 smile561607154 创建的主题 Go 编程语言 有没有人来实现一下这个功能
gpt 回答,看是否有用
-----------
可以使用 Go 内置的 encoding/json 包将 JSON 解析成一个结构体。以下是一个 Go 示例代码:

package main

import (
"encoding/json"
"fmt"
)

// JSON 对应的结构体
type Config struct {
Server1 struct {
Domain string `json:"domain"`
Api struct {
Api1 string `json:"api1"`
} `json:"api"`
} `json:"server1"`
Server2 struct {
Domain string `json:"domain"`
Api struct {
Api2 string `json:"api2"`
} `json:"api"`
} `json:"server2"`
}

// Api 类型封装了 server 的信息和 API 的路径
type Api struct {
baseURL string
path string
}

// NewApi 方法创建一个 Api 对象
func NewApi(config *Config, serverName string, apiName string) *Api {
api := &Api{}

switch serverName {
case "server1":
api.baseURL = config.Server1.Domain
switch apiName {
case "api1":
api.path = config.Server1.Api.Api1
default:
panic(fmt.Sprintf("unsupported API: %s", apiName))
}
case "server2":
api.baseURL = config.Server2.Domain
switch apiName {
case "api2":
api.path = config.Server2.Api.Api2
default:
panic(fmt.Sprintf("unsupported API: %s", apiName))
}
default:
panic(fmt.Sprintf("unsupported server: %s", serverName))
}

return api
}

// URL 方法返回拼接过的完整 URL
func (api *Api) URL() string {
return api.baseURL + api.path
}

func main() {
// 假设这是从 HTTP 响应体中获取的 JSON 数据
jsonStr := `
{
"server1": {
"domain": "https://www.baidu.com",
"api": {
"api1": "/api1"
}
},
"server2": {
"domain": "https://www.google.com",
"api": {
"api2": "/api2"
}
}
}
`

// 将 JSON 解析成结构体
var config Config
err := json.Unmarshal([]byte(jsonStr), &config)
if err != nil {
panic(err)
}

// 创建 API 对象并输出 URL
api1 := NewApi(&config, "server1", "api1")
fmt.Println(api1.URL()) // 输出 https://www.baidu.com/api1

api2 := NewApi(&config, "server2", "api2")
fmt.Println(api2.URL()) // 输出 https://www.google.com/api2
}
-----------
297 天前
回复了 swordfairy 创建的主题 路由器 宽带升级,求路由器推荐
@Donahue 对,有线的话没啥问题, 就是无线感觉有点跟不上了,想升级无线方面的
@scemsjyd 这个是什么时期的大王卡呀,是联通的嘛
322 天前
回复了 swordfairy 创建的主题 程序员 求推荐时间轴类的笔记软件
@wheeler 这个看着不错,就是设备要求的版本有点高了
@DavZhn 辛苦推荐一下办理的方式
1  2  3  4  5  6  7  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1040 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
Developed with CodeLauncher
♥ Do have faith in what you're doing.