當前位置: 首頁>>代碼示例>>Golang>>正文


Golang box.NewConfigSource函數代碼示例

本文整理匯總了Golang中github.com/ttacon/box.NewConfigSource函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConfigSource函數的具體用法?Golang NewConfigSource怎麽用?Golang NewConfigSource使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewConfigSource函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	eventStream := c.EventService().Channel(32)
	for eve := range eventStream {
		fmt.Println("got event: ", pretty.Sprintf("%#v\n", eve))
	}
}
開發者ID:superuser123,項目名稱:box,代碼行數:36,代碼來源:main.go

示例2: main

func main() {
	flag.Parse()

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, folder, err := c.FolderService().GetTrashedFolder("2303056557")
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Print(folder)

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}
開發者ID:superuser123,項目名稱:box,代碼行數:33,代碼來源:main.go

示例3: main

func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*fileId) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	var lock *box.Lock
	if len(*expiresAt) != 0 {
		lock = &box.Lock{
			Type:                "lock",
			ExpiresAt:           *expiresAt,
			IsDownloadPrevented: false,
		}
	}

	resp, err := c.FileService().Lock(*fileId, lock)
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)

	// Print out the new tokens for next time
	fmt.Printf("\n%#v\n", tok)
}
開發者ID:superuser123,項目名稱:box,代碼行數:48,代碼來源:main.go

示例4: main

func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*fileId) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, err := c.FileService().DownloadFile(*fileId)
	pretty.Print(resp)
	fmt.Println("err: ", err)

	// Read the content into bs
	var bs []byte
	defer resp.Body.Close()
	bs, err = ioutil.ReadAll(resp.Body)
	fmt.Println("ioutil.ReadAll err: ", err)
	fmt.Printf("read %d bytes", len(bs))

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}
開發者ID:wyc,項目名稱:box,代碼行數:46,代碼來源:main.go

示例5: main

func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*membershipID) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "https://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	// NOTE:
	// There seem to be restriction on what "roles" one can pass in, I need
	// to track done the definitive list.
	resp, membershipEntry, err := c.GroupService().UpdateMembership(
		*membershipID, *role)
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Println(membershipEntry)
	// Print out the new tokens for next time
	fmt.Printf("\n%#v\n", tok)
}
開發者ID:superuser123,項目名稱:box,代碼行數:43,代碼來源:main.go

示例6: main

func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*link) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, sharedItem, err := c.SharedService().GetItem(*link, *password)
	fmt.Printf("%#v\n", resp)
	fmt.Println("err: ", err)
	pretty.Println(sharedItem)

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}
開發者ID:superuser123,項目名稱:box,代碼行數:40,代碼來源:main.go


注:本文中的github.com/ttacon/box.NewConfigSource函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。