go mod init example.com/my-golib-demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| r.POST("/users", func(c *gin.Context) { | |
| var user struct { | |
| Name string `json:"name"` | |
| Email string `json:"email"` | |
| } | |
| if err := c.BindJSON(&user); err != nil { | |
| c.JSON(400, gin.H{"error": err.Error()}) | |
| return | |
| } | |
| // TODO: create user in database |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| r.GET("/users", func(c *gin.Context) { | |
| users := []string{"Alice", "Bob", "Charlie"} | |
| c.JSON(200, gin.H{ | |
| "users": users, | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Author: Mitch Allen | |
| * File: server.go | |
| */ | |
| package main | |
| import "github.com/gin-gonic/gin" | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/mitchallen/go-lib" | |
| ) | |
| func main() { | |
| fmt.Println(lib.Add(2, 3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Author: Mitch Allen | |
| * File: go-lib_test.go | |
| */ | |
| package lib | |
| import ( | |
| "testing" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Author: Mitch Allen | |
| * File: go-lib.go | |
| */ | |
| package lib | |
| // Returns the sum of two numbers | |
| func Add(a int, b int) int { | |
| return a + b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Author: Mitch Allen | |
| * File: init.go | |
| */ | |
| package lib | |
| import ( | |
| "fmt" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Author: Mitch Allen | |
| // File: app.js | |
| import { weightedChoice } from './weighted-choice.js'; | |
| let canvas = document.getElementById("canvas"); | |
| const SCREEN_SIZE = 300; | |
| const DIM = 10; | |
| const CELL_SIZE = SCREEN_SIZE / DIM; | |
| const BORDER = 1.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| canvas { | |
| padding: 0; | |
| margin: auto; | |
| display: block; | |
| width: 400px; | |
| height: 400px; | |
| position: absolute; | |
| top: 0; | |
| bottom: 0; | |
| left: 0; |