第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

GoLang 打印結(jié)構(gòu)中變量的值

GoLang 打印結(jié)構(gòu)中變量的值

Go
慕村225694 2022-10-31 15:45:31
我不是 GoLang 專家,但我需要對項(xiàng)目進(jìn)行故障排除。現(xiàn)在我嘗試打印相同變量的值,但我收到的輸出是地址而不是值:attrs := core.Attributes{}    err = rtrV1.SetAttributesStruct(&attrs, sessAttrs, session.NasIP, ipv4Session, ipv6Session)    if err1, ok := err.(core.SessionNotFoundError); ok {        apiH.Logger.Info(err1.Error())        c.JSON(404, gin.H{"message": err.Error()})        return    } else if err != nil {        apiH.Logger.Error(err.Error())        c.JSON(500, gin.H{"message": "internal error"})        return    }    err = core.MakeNASProxyRequest(apiH.HttpClient, nasproxyHost, nasproxyPort, authToken, attrs)    debugAttrs := fmt.Sprintf("%+p", attrs)    debugAttrs2 := fmt.Sprintf("%+v", attrs)        apiH.Logger.Info("attrs:"+" "+debugAttrs, log.Field("type", "serve-request"))    apiH.Logger.Info("attr2:"+" "+debugAttrs2, log.Field("type", "serve-request"))我需要打印attrs,但我收到了這個輸出:"msg":"attrs: %!p(core.Attributes={+0xc000420460 <nil> <nil> +0xc000238c60 <nil> <nil> <nil> <nil> +0xc000238c98 <nil> <nil> <nil> <nil>})""msg":"attr2: {NASIPAddress:0xc000420460 NASIdentifier:<nil> NASIPv6Address:<nil> Username:0xc000238c60 NASPort:<nil> FramedIPAddress:<nil> CalledStationID:<nil> CallingStationID:<nil> AcctSessionID:0xc000238c98 AcctMultiSessionID:<nil> NASPortID:<nil> FramedInterfaceID:<nil> FramedIPv6Prefix:<nil>}"如何打印值?謝謝您的幫助
查看完整描述

2 回答

?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個贊

您可以使用fmt包或 JSON 編組來打印結(jié)構(gòu)值...例如


import "fmt"


type Person struct {

    FirstName string

}


func main() {

    p := &Person{"mr1"}

    fmt.Printf("%+v", p)

}

或者


import (

    "encoding/json"

    "fmt"

)


type Person struct {

    FirstName string

}


func main() {

    p := &Person{"mr1"}

    s, _ := json.Marshal(p)

    fmt.Printf("%s\n", s)

}


查看完整回答
反對 回復(fù) 2022-10-31
?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個贊

你可以使用深漂亮的打印機(jī)。進(jìn)口:github.com/davecgh/go-spew/spew

例子:

spew.Dump(attrs)


查看完整回答
反對 回復(fù) 2022-10-31
  • 2 回答
  • 0 關(guān)注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號