1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  | 
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// this is similar to 'gin' but specifically only for
// sending and working with protocol buffers
//
// also, it is as close to possible a golang 'primitive'
// package (there is no go.sum file)
import (
	"net/http"
	"github.com/gin-gonic/gin"
	"go.wit.com/lib/http/ginpb"
)
func handlePort(port int) {
	r := ginpb.Default()
	// Ping test
	r.GET("/ping", func(c *ginpb.Context) {
		// c.String(http.StatusOK, "pong")
	})
	// Get user value
	r.GET("/user/:name", func(c *ginpb.Context) {
		// c.JSON(http.StatusOK, gin.H{"user": "test", "status": "no value"})
		/*
			user := c.Params.ByName("name")
			value, ok := db[user]
			if ok {
				c.JSON(http.StatusOK, ginpb.H{"user": user, "value": value})
			} else {
				c.JSON(http.StatusOK, ginpb.H{"user": user, "status": "no value"})
			}
		*/
	})
}
func handlePortGin(port int) {
	r := gin.Default()
	// Ping test
	r.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "pong")
	})
	// Get user value
	r.GET("/user/:name", func(c *gin.Context) {
		user := c.Params.ByName("name")
		c.JSON(http.StatusOK, gin.H{"user": user, "status": "no value"})
	})
}
  |