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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何從以下 golang 函數(shù)生成具有 TTL 8h 的令牌?

如何從以下 golang 函數(shù)生成具有 TTL 8h 的令牌?

Go
湖上湖 2022-10-24 15:49:58
我是編程新手,不知道在我的客戶端 golang 程序的源代碼中使用令牌生成客戶端 api 函數(shù)。尋求一些建議。太感謝了。源碼包:https ://pkg.go.dev/github.com/gravitational/teleport/api/client#Client.UpsertToken函數(shù)源代碼:func (c *Client) UpsertToken(ctx context.Context, token types.ProvisionToken) error {    tokenV2, ok := token.(*types.ProvisionTokenV2)    if !ok {        return trace.BadParameter("invalid type %T", token)    }    _, err := c.grpc.UpsertToken(ctx, tokenV2, c.callOpts...)    return trail.FromGRPC(err)}My code:package mainimport (    "context"    "crypto/tls"    "fmt"    "log"    "os"    "strings"    "time"    "github.com/gravitational/teleport/api/client"    "github.com/gravitational/teleport/api/client/proto"    "google.golang.org/grpc")// Client is a gRPC Client that connects to a Teleport Auth server either// locally or over ssh through a Teleport web proxy or tunnel proxy.//// This client can be used to cover a variety of Teleport use cases,// such as programmatically handling access requests, integrating// with external tools, or dynamically configuring Teleport.type Client struct {    // c contains configuration values for the client.    //c Config    // tlsConfig is the *tls.Config for a successfully connected client.    tlsConfig *tls.Config    // dialer is the ContextDialer for a successfully connected client.    //dialer ContextDialer    // conn is a grpc connection to the auth server.    conn *grpc.ClientConn    // grpc is the gRPC client specification for the auth server.    grpc proto.AuthServiceClient    // closedFlag is set to indicate that the connnection is closed.    // It's a pointer to allow the Client struct to be copied.    closedFlag *int32    // callOpts configure calls made by this client.    callOpts []grpc.CallOption}/*type ProvisionToken interface {    Resource    // SetMetadata sets resource metatada    SetMetadata(meta Metadata)    // GetRoles returns a list of teleport roles    // that will be granted to the user of the token    // in the crendentials}輸出:語法錯(cuò)誤而不是創(chuàng)建令牌
查看完整描述

1 回答

?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊

看來您的代碼有很多錯(cuò)誤。而且,很明顯您遇到了語法錯(cuò)誤。我相信您會(huì)在控制臺(tái)中獲得實(shí)際發(fā)生這些語法錯(cuò)誤的行號(hào)。


請(qǐng)理解 Golang 的語法以及如何調(diào)用函數(shù)以及我應(yīng)該向這些函數(shù)傳遞多少參數(shù)。


在查看您的代碼后,我想指出幾個(gè)錯(cuò)誤。


//It shouldn't be like this

ctx, err, token, err2 := clt.UpsertToken(ctx, token)


//Instead it should be like this

 err := clt.UpsertToken(ctx, token)

//The return type of UpsertToken() method is error, you should use only one variable to receive this error.

strings.Contains()函數(shù)有兩個(gè)參數(shù),但你傳遞了四個(gè)。

請(qǐng)參閱此文檔以獲取string.Contains()

您正在使用循環(huán)內(nèi)的條件和從不分配t := 0和檢查它。ifforincremented

請(qǐng)參閱本文檔以獲取fmt.Printf()

參考這個(gè)功能

刪除所有語法錯(cuò)誤,然后只有您的代碼將運(yùn)行并交叉檢查您的邏輯。

如果您想查看語法錯(cuò)誤示例,請(qǐng)?jiān)诖颂幉榭矗?a >https ://go.dev/play/p/Hhu48UqlPRF


查看完整回答
反對(duì) 回復(fù) 2022-10-24
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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