From f4654bf4465a4187016331ab96d887cca095546c Mon Sep 17 00:00:00 2001 From: John Date: Wed, 27 Nov 2019 23:19:07 +0800 Subject: [PATCH] fix comment issue in example codes for gmap --- .example/container/gmap/basic.go | 2 +- .example/other/test.go | 15 +++++++++--- net/ghttp/ghttp_unit_mess_test.go | 39 +++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 net/ghttp/ghttp_unit_mess_test.go diff --git a/.example/container/gmap/basic.go b/.example/container/gmap/basic.go index 5b4499ab5..4fb984930 100644 --- a/.example/container/gmap/basic.go +++ b/.example/container/gmap/basic.go @@ -9,7 +9,7 @@ import ( func main() { // 创建一个默认的gmap对象, // 默认情况下该gmap对象不支持并发安全特性, - // 初始化时可以给定true参数关闭并发安全特性,当做一个普通的map使用。 + // 初始化时可以给定true参数开启并发安全特性,用以并发安全场景。 m := gmap.New() // 设置键值对 diff --git a/.example/other/test.go b/.example/other/test.go index e29d2268f..cae1bef07 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,10 +1,19 @@ package main import ( - "fmt" - "github.com/gogf/gf/text/gstr" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" ) func main() { - fmt.Println(gstr.CamelCase("/auth/routerName.html")) + s := g.Server() + s.SetIndexFolder(true) + s.BindHandler("/admin.html", func(r *ghttp.Request) { + r.Response.Write("admin") + }) + s.BindHandler("/admin-do-{page}.html", func(r *ghttp.Request) { + r.Response.Write("admin-do-" + r.GetString("page")) + }) + s.SetPort(8999) + s.Run() } diff --git a/net/ghttp/ghttp_unit_mess_test.go b/net/ghttp/ghttp_unit_mess_test.go new file mode 100644 index 000000000..fdb232aff --- /dev/null +++ b/net/ghttp/ghttp_unit_mess_test.go @@ -0,0 +1,39 @@ +// Copyright 2018 gf Author(https://github.com/gogf/gf). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package ghttp_test + +import ( + "fmt" + "testing" + "time" + + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/test/gtest" +) + +func Test_GetUrl(t *testing.T) { + p := ports.PopRand() + s := g.Server(p) + s.BindHandler("/url", func(r *ghttp.Request) { + r.Response.Write(r.GetUrl()) + }) + s.SetPort(p) + s.SetDumpRouteMap(false) + s.Start() + defer s.Shutdown() + + time.Sleep(100 * time.Millisecond) + gtest.Case(t, func() { + prefix := fmt.Sprintf("http://127.0.0.1:%d", p) + client := ghttp.NewClient() + client.SetBrowserMode(true) + client.SetPrefix(prefix) + + gtest.Assert(client.GetContent("/url"), prefix+"/url") + }) +}