当前位置: 首页>>代码示例>>Golang>>正文


Golang kami.Get函数代码示例

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


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

示例1: main

func main() {
	dbMap := InitDB()
	defer dbMap.Db.Close()
	dbMap.TraceOn("[gorp]", log.New(os.Stdout, "scribble: ", log.Lmicroseconds))

	ctx := context.Background()
	kami.Context = context.WithValue(ctx, "db", dbMap)

	// Middlwares
	kami.Use("/api/", auth.AuthMiddleware)

	// Authentication APIs
	kami.Post("/api/register", handler.Register)
	kami.Post("/api/login", handler.Login)
	kami.Post("/api/logout", handler.Logout)

	// Note APIs
	kami.Get("/api/notes", handler.ListNotes)
	kami.Post("/api/notes", handler.AddNote)
	kami.Get("/api/notes/:noteId", handler.GetNote)
	kami.Put("/api/notes/:noteId", handler.UpdateNote)
	kami.Delete("/api/notes/:noteId", handler.DeleteNote)

	kami.Serve()
}
开发者ID:keichi,项目名称:scribble,代码行数:25,代码来源:main.go

示例2: main

func main() {
	c := cron.New()
	c.AddFunc("5 * * * * *", Hoge)   // 毎分5秒
	c.AddFunc("*/5 * * * * *", Fuga) // 5秒毎

	c.Start()
	isRunning := true

	kami.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("OK"))
	})
	kami.Get("/start", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		if !isRunning {
			c.Start()
			isRunning = true
		}
		w.Write([]byte("START OK"))
	})
	kami.Get("/stop", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		if isRunning {
			c.Stop()
			isRunning = false
		}
		w.Write([]byte("STOP OK"))
	})

	defer func() {
		if isRunning {
			c.Stop()
			isRunning = false
		}
	}()

	kami.Serve()
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:35,代码来源:main.go

示例3: BenchmarkMiddleware5Afterware1

func BenchmarkMiddleware5Afterware1(b *testing.B) {
	kami.Reset()
	numbers := []int{1, 2, 3, 4, 5}
	for _, n := range numbers {
		n := n // wtf
		kami.Use("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
			return context.WithValue(ctx, n, n)
		})
	}
	kami.After("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		for _, n := range numbers {
			if ctx.Value(n) != n {
				panic(n)
			}
		}
		return ctx
	})
	kami.Get("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		for _, n := range numbers {
			if ctx.Value(n) != n {
				w.WriteHeader(http.StatusServiceUnavailable)
				return
			}
		}
	})
	req, _ := http.NewRequest("GET", "/test", nil)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		kami.Handler().ServeHTTP(resp, req)
	}
}
开发者ID:hoshitocat,项目名称:kami,代码行数:32,代码来源:bench_test.go

示例4: main

func main() {
	flag.Parse()

	switch flag.Arg(0) {

	case "index":
		search.Index(flag.Arg(1))

	case "search":
		search.OpenIndex()

		result, err := search.Search(flag.Arg(1))
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(result)

	case "server":
		search.OpenIndex()

		kami.Get("/search/:keyword", searchHandler)
		kami.Serve()
	}
}
开发者ID:misakik,项目名称:f3,代码行数:25,代码来源:server.go

示例5: BenchmarkMiddleware5

func BenchmarkMiddleware5(b *testing.B) {
	kami.Reset()
	numbers := []int{1, 2, 3, 4, 5}
	for _, n := range numbers {
		n := n // wtf
		kami.Use("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
			return context.WithValue(ctx, n, n)
		})
	}
	kami.Get("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		for _, n := range numbers {
			if ctx.Value(n) != n {
				w.WriteHeader(501)
				return
			}
		}
	})
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		req, _ := http.NewRequest("GET", "/test", nil)
		kami.Handler().ServeHTTP(resp, req)
		if resp.Code != 200 {
			panic(resp.Code)
		}
	}
}
开发者ID:gunosy,项目名称:kami,代码行数:26,代码来源:bench_test.go

示例6: main

func main() {
	ctx := context.Background()
	kami.Context = ctx // set our "god context", the base context for all requests

	kami.Use("/", greetMiddleware)  // use this middleware for paths under /hello/
	kami.Get("/hello/:name", greet) // add a GET handler with a parameter in the URL
	kami.Serve()                    // gracefully serve with support for einhorn and systemd
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:8,代码来源:kami.go

示例7: routeBench

func routeBench(b *testing.B, route string) {
	kami.Reset()
	kami.Use("/Z/", noopMW)
	kami.After("/Z/", noopMW)
	kami.Get(route, noop)
	req, _ := http.NewRequest("GET", route, nil)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		kami.Handler().ServeHTTP(resp, req)
	}
}
开发者ID:hoshitocat,项目名称:kami,代码行数:12,代码来源:bench_test.go

示例8: BenchmarkStaticRoute

func BenchmarkStaticRoute(b *testing.B) {
	kami.Reset()
	kami.Get("/hello", noop)
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		req, _ := http.NewRequest("GET", "/hello", nil)
		kami.Handler().ServeHTTP(resp, req)
		if resp.Code != 200 {
			panic(resp.Code)
		}
	}
}
开发者ID:gunosy,项目名称:kami,代码行数:12,代码来源:bench_test.go

示例9: BenchmarkParameter

func BenchmarkParameter(b *testing.B) {
	kami.Reset()
	kami.Get("/hello/:name", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		kami.Param(ctx, "name")
	})
	req, _ := http.NewRequest("GET", "/hello/bob", nil)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		kami.Handler().ServeHTTP(resp, req)
	}
}
开发者ID:hoshitocat,项目名称:kami,代码行数:12,代码来源:bench_test.go

示例10: BenchmarkParameter5

func BenchmarkParameter5(b *testing.B) {
	kami.Reset()
	kami.Get("/:a/:b/:c/:d/:e", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		for _, v := range []string{"a", "b", "c", "d", "e"} {
			kami.Param(ctx, v)
		}
	})
	req, _ := http.NewRequest("GET", "/a/b/c/d/e", nil)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		kami.Handler().ServeHTTP(resp, req)
	}
}
开发者ID:hoshitocat,项目名称:kami,代码行数:14,代码来源:bench_test.go

示例11: BenchmarkMiddleware

func BenchmarkMiddleware(b *testing.B) {
	kami.Reset()
	kami.Use("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		return context.WithValue(ctx, "test", "ok")
	})
	kami.Get("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		if ctx.Value("test") != "ok" {
			w.WriteHeader(http.StatusServiceUnavailable)
		}
	})
	req, _ := http.NewRequest("GET", "/test", nil)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		kami.Handler().ServeHTTP(resp, req)
	}
}
开发者ID:hoshitocat,项目名称:kami,代码行数:17,代码来源:bench_test.go

示例12: TestCloseHandler

func TestCloseHandler(t *testing.T) {
	called := false
	closeHandler := func(ctx context.Context, r *http.Request) {
		called = true
	}

	kami.Reset()

	kami.CloseHandler = closeHandler
	kami.Get("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		t.Log("TestCloseHandler")
	})

	expectResponseCode(t, "GET", "/test", http.StatusOK)
	if called != true {
		t.Fatal("expected closeHandler to be called")
	}
}
开发者ID:SLASH2NL,项目名称:kami,代码行数:18,代码来源:kami_test.go

示例13: BenchmarkMiddlewareAfterwareMiss

// This tests just the URL walking middleware engine.
func BenchmarkMiddlewareAfterwareMiss(b *testing.B) {
	kami.Reset()
	kami.Use("/dog/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		return nil
	})
	kami.After("/dog/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		return nil
	})
	kami.Get("/a/bbb/cc/d/e", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
	})
	req, _ := http.NewRequest("GET", "/a/bbb/cc/d/e", nil)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		kami.Handler().ServeHTTP(resp, req)
	}
}
开发者ID:hoshitocat,项目名称:kami,代码行数:19,代码来源:bench_test.go

示例14: TestKami

func TestKami(t *testing.T) {
	kami.Reset()
	kami.Use("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		return context.WithValue(ctx, "test1", "1")
	})
	kami.Use("/v2/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		return context.WithValue(ctx, "test2", "2")
	})
	kami.Get("/v2/papers/:page", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		page := kami.Param(ctx, "page")
		if page == "" {
			panic("blank page")
		}
		io.WriteString(w, page)

		test1 := ctx.Value("test1").(string)
		test2 := ctx.Value("test2").(string)

		if test1 != "1" || test2 != "2" {
			t.Error("unexpected ctx value:", test1, test2)
		}
	})

	resp := httptest.NewRecorder()
	req, err := http.NewRequest("GET", "/v2/papers/3", nil)
	if err != nil {
		t.Fatal(err)
	}

	kami.Handler().ServeHTTP(resp, req)
	if resp.Code != http.StatusOK {
		t.Error("should return HTTP OK", resp.Code, "≠", http.StatusOK)
	}

	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	if string(data) != "3" {
		t.Error("expected page 3, got", string(data))
	}
}
开发者ID:SLASH2NL,项目名称:kami,代码行数:43,代码来源:kami_test.go

示例15: BenchmarkMiddleware

func BenchmarkMiddleware(b *testing.B) {
	kami.Reset()
	kami.Use("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		return context.WithValue(ctx, "test", "ok")
	})
	kami.Get("/test", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		if ctx.Value("test") != "ok" {
			w.WriteHeader(501)
		}
	})
	for n := 0; n < b.N; n++ {
		resp := httptest.NewRecorder()
		req, _ := http.NewRequest("GET", "/test", nil)
		kami.Handler().ServeHTTP(resp, req)
		if resp.Code != 200 {
			panic(resp.Code)
		}
	}
}
开发者ID:gunosy,项目名称:kami,代码行数:19,代码来源:bench_test.go


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