diff options
| author | Jeff Carr <[email protected]> | 2025-03-18 15:14:06 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-18 15:14:06 -0500 |
| commit | 9e7887ae88b1d60902b6348d8ee0876ab679f915 (patch) | |
| tree | 8879f6bf38745bb6910cc05b33f8617024b82a34 /gin.go | |
| parent | b96f3ce26dc518c165f1939be1f5b7ed6f2e8701 (diff) | |
misc
Diffstat (limited to 'gin.go')
| -rw-r--r-- | gin.go | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +// 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 *gin.Context) { + c.String(http.StatusOK, "pong") + }) + + // Get user value + r.GET("/user/:name", func(c *gin.Context) { + user := c.Params.ByName("name") + value, ok := db[user] + if ok { + c.JSON(http.StatusOK, gin.H{"user": user, "value": value}) + } else { + c.JSON(http.StatusOK, gin.H{"user": user, "status": "no value"}) + } + }) + +} |
