• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang objx.MustFromBase64函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/stretchr/objx.MustFromBase64函数的典型用法代码示例。如果您正苦于以下问题:Golang MustFromBase64函数的具体用法?Golang MustFromBase64怎么用?Golang MustFromBase64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MustFromBase64函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: serveHTTP

func (r *room) serveHTTP(w http.ResponseWriter, req *http.Request) {
	socket, err := upgrader.Upgrade(w, req, nil)
	if err != nil {
		log.Fatal("ServeHTTP: ", err)
		return
	}

	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("Failed to get auth cookie:", err)
		return
	}

	client := &client{
		socket:   socket,
		send:     make(chan *message, messageBufferSize),
		room:     r,
		userData: objx.MustFromBase64(authCookie.Value),
	}

	r.join <- client
	defer func() { r.leave <- client }()
	go client.read()
	client.write()
}
开发者ID:NikitaSmall,项目名称:gochat,代码行数:25,代码来源:room.go


示例2: ServeHTTP

func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	socket, err := upgrader.Upgrade(w, req, nil)
	// Upgrade upgrades the HTTP server connection to the WebSocket protocol.

	if err != nil {
		log.Fatal("ServeHTTP:", err)
		return
	}

	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("クッキーの取得に失敗しました:", err)
		return
	}

	client := &client{
		socket:   socket,
		send:     make(chan *message, messageBufferSize),
		room:     r,
		userData: objx.MustFromBase64(authCookie.Value),
	}

	r.join <- client
	defer func() {
		r.leave <- client
	}()

	go client.write()

	client.read()
}
开发者ID:toromoti,项目名称:study-golang,代码行数:31,代码来源:room.go


示例3: ServeHTTP

func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) {

	// need to upgrade socket (HTTP Request) into webSocket
	socket, err := upgrader.Upgrade(w, req, nil)

	if err != nil {
		log.Fatal("ServeHTTP:", err)
		return
	}

	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("Failed to get auth cookie:", err)
		return
	}

	// creates a client that will join a channel later on
	client := &client{
		socket:   socket,
		send:     make(chan *message, messageBufferSize),
		room:     r, // weird as it is this ',' is correct
		userData: objx.MustFromBase64(authCookie.Value),
	}

	// makes client join (in other words, sends message to 'join' channel)
	r.join <- client

	// makes client leave but defer it to ensure clients successfuly join first
	defer func() { r.leave <- client }() // similar to JS promises
	go client.write()                    // goroutine, in other words, run this portion of code in a new thread
	client.read()

}
开发者ID:heitorlessa,项目名称:golearning,代码行数:33,代码来源:room.go


示例4: ServeHTTP

func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// UpgradeでWebSocketコネクションを取得する
	socket, err := upgrader.Upgrade(w, req, nil)
	if err != nil {
		log.Fatal("ServeHTTP:", err)
	}

	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("クッキーの取得に失敗しました: ", err)
		return
	}

	client := &client{
		socket:   socket,
		send:     make(chan *message, messageBufferSize),
		room:     r,
		userData: objx.MustFromBase64(authCookie.Value),
	}

	r.join <- client
	defer func() { r.leave <- client }()
	go client.write() // goroutineとして呼び出される
	client.read()
}
开发者ID:khirayama,项目名称:go-training,代码行数:25,代码来源:room.go


示例5: ServeHTTP

func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// In order to use web sockets, we must upgrade the HTTP
	// connection using the websocket.Upgrader, which is reusable
	socket, err := upgrader.Upgrade(w, req, nil)
	if err != nil {
		log.Fatal("ServeHTTP:", err)
		return
	}

	// get the user data from the auth cookie
	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("Failed to get auth cookie:", err)
		return
	}

	client := &client{
		socket: socket,
		send:   make(chan *message, messageBufferSize),
		room:   r,
		// store the user data in client
		userData: objx.MustFromBase64(authCookie.Value),
	}

	r.join <- client
	defer func() { r.leave <- client }()

	// run the write method as a go routine
	// in a different thread
	go client.write()
	// call in the main thread which will block
	// operations(keeping the connection alive)
	// until it's time to close it
	client.read()
}
开发者ID:liyu-wang,项目名称:go-chat,代码行数:35,代码来源:room.go


示例6: ServeHTTP

// ServeHTTPメソッドを定義することで*roomはhttp.Handlerとして扱えるようになる
// HTTPリクエストが発生した場合
func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// WebSocketコネクションの取得
	socket, err := upgrader.Upgrade(w, req, nil)
	if err != nil {
		log.Fatal("ServeHTTP:", err)
		return
	}
	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("Failed to get auth cookie:", err)
		return
	}
	// クライアントの生成
	client := &client{
		socket:   socket,
		send:     make(chan *message, messageBufferSize),
		room:     r,
		userData: objx.MustFromBase64(authCookie.Value),
	}

	r.join <- client
	// クライアントの終了時に退室する
	defer func() { r.leave <- client }()
	// goroutineとして実行される
	// 別スレッドで実行される
	// ※メインスレッドで実行されることもある
	go client.write()
	// 接続は保持され、終了を指示されるまで他の処理はブロックされる
	client.read()
}
开发者ID:keiwt,项目名称:goblueprints,代码行数:32,代码来源:room.go


示例7: ServeHTTP

// means a room can now act as a handler
func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// In order to use web sockets, we must upgrade the HTTP connection using
	// the websocket.Upgrader type, which is reusable so we need only create one.
	socket, err := upgrader.Upgrade(w, req, nil)
	if err != nil {
		log.Fatal("ServeHTTP: ", err)
		return
	}

	authCookie, err := req.Cookie("auth")
	if err != nil {
		log.Fatal("Failed to get auth cookie:", err)
		return
	}

	client := &client{
		socket:   socket,
		send:     make(chan *message, messageBufferSize),
		room:     r,
		userData: objx.MustFromBase64(authCookie.Value),
	}
	r.join <- client
	// will call after the operation finished
	defer func() {
		r.leave <- client
	}()
	// The write method for the client is then called as a Go routine
	// the word go followed by a space character
	go client.write()
	client.read()
}
开发者ID:rabbitcount,项目名称:goblueprints,代码行数:32,代码来源:room.go


示例8: ServeHTTP

func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	t.once.Do(func() {
		t.templ = template.Must(template.ParseFiles(filepath.Join("templates", t.filename)))
	})
	data := map[string]interface{}{
		"Host": r.Host,
	}
	if authCookie, err := r.Cookie("auth"); err == nil {
		data["UserData"] = objx.MustFromBase64(authCookie.Value)
	}
	t.templ.Execute(w, data)
}
开发者ID:bonegollira,项目名称:gogo,代码行数:12,代码来源:main.go


示例9: ServeHTTP

func (t *templateHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	// no matter how many go routines call it , the function inside do will be executed once only
	t.once.Do(func() {
		t.templ = template.Must(template.ParseFiles(filepath.Join("templates", t.filename)))
	})
	data := map[string]interface{}{
		"Host": req.Host,
	}
	if authCookie, err := req.Cookie("auth"); err == nil {
		data["UserData"] = objx.MustFromBase64(authCookie.Value)
	}
	t.templ.Execute(rw, data)
}
开发者ID:gopher2121,项目名称:gocode,代码行数:13,代码来源:main.go


示例10: ServeHTTP

func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

	t.once.Do(func() { //此处代码只执行一次 多个携程中也只执行一次
		t.temp1 = template.Must(template.ParseFiles(filepath.Join("tpl", t.filename)))
	})
	data := map[string]interface{}{
		"Host": r.Host,
	}

	if authCookie, err := r.Cookie("auth"); err == nil {
		data["UserData"] = objx.MustFromBase64(authCookie.Value)
	}

	if err := t.temp1.Execute(w, data); err != nil {
		fmt.Println(err)
	}
}
开发者ID:oywc410,项目名称:MYPG,代码行数:17,代码来源:main.go


示例11: ServeHTTP

// ServeHTTP handles the HTTP request.
func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// the sync.Once type guarantees that the function
	// we pass as an argument will only be executae once,
	// regardless of how many goroutines are calling ServeHTTP
	t.once.Do(func() {
		t.templ = template.Must(template.ParseFiles(filepath.Join("templates", t.filename)))
	})

	// create a data object to serve the template
	data := map[string]interface{}{
		"Host": r.Host,
	}
	// store the auth info from cookie into the data obj if there is any
	if authCookie, err := r.Cookie("auth"); err == nil {
		data["UserData"] = objx.MustFromBase64(authCookie.Value)
	}
	// t.templ.Execute(w, r)
	t.templ.Execute(w, data)
}
开发者ID:liyu-wang,项目名称:go-chat,代码行数:20,代码来源:main.go



注:本文中的github.com/stretchr/objx.MustFromBase64函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang objx.MustFromURLQuery函数代码示例发布时间:2022-05-28
下一篇:
Golang objx.MSI函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap