[PHP翻译成Golang] explode后直接把拆分结果list到多个变量里面,在GO里面怎么简洁实现

//假设有固定格式变量authorization
$authorization = "10000|mobile,email,avavtar"

//我要以 `|` 作为分割,将结果变为两个变量
user_id = "10000"
scope = "mobile,email,avavtar"

//在php中,只需要
list($user_id, $scope) = explode($authorization, "|");

//而在Golang中,我只知道使用 strings.Split 切割,返回结果是一个string切片
authorization_split := strings.Split(authorization, "|")
user_id := authorization_split[0]
scope := authorization_split[1]

这样的操作让我觉得有些许繁琐,请问在Go中是否具有这样的方法,直接将切片复制给多个变量

Inhere
最佳答案

可以直接使用 strings.Cut() 总是切分为两段返回

推荐下 Go 工具包库 github.com/gookit/goutil

1年前 评论
looooooook 1年前
讨论数量: 5
goStruct

user_id ,scope:= authorization_split[0],authorization_split[1]

1年前 评论
唐章明 (楼主) 1年前
goStruct

都用go了就没必要以php方式写go吧,两者本身差异就挺大。

1年前 评论
Inhere

可以直接使用 strings.Cut() 总是切分为两段返回

推荐下 Go 工具包库 github.com/gookit/goutil

1年前 评论
looooooook 1年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!