This file contains 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
type HandlerData struct { | |
data string | |
//whatever | |
} | |
func main(){ | |
//Create a data struct | |
// add data to struct | |
h := &HandlerData{...} |
This file contains 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" | |
"http" | |
"flag" | |
"runtime" | |
"bytes" | |
"log" | |
) |
This file contains 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
include $(GOROOT)/src/Make.inc | |
PROTOFILES=$(wildcard *.proto) | |
GOPROTOFILES=$(patsubst %.proto,%.pb.go,$(PROTOFILES)) | |
TARG=protopackage | |
GOFILES=\ | |
$(GOPROTOFILES)\ | |
CLEANFILES+=$(GOPROTOFILES) |
This file contains 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 ( | |
"crypto/tls" | |
"io" | |
"log" | |
) | |
func main() { | |
conn, err := tls.Dial("tcp", "127.0.0.1:8000", nil) |
This file contains 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 ( | |
"bytes" | |
"exec" | |
"log" | |
"os" | |
) | |
// Pipeline strings together the given exec.Cmd commands in a similar fashion |
This file contains 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
// Leetcode: | |
// https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/ | |
func maxValueOfCoins(piles [][]int, k int) int { | |
// Record the points cumulatively for taking N coins from each pile | |
for p := range piles { | |
for c := range piles[p] { | |
if c+1 >= len(piles[p]) { | |
continue | |
} |
This file contains 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" | |
import "regexp" | |
var email = regexp.MustCompile(`^[^@]+@[^@.]+\.[^@.]+$`) | |
var shortPhone = regexp.MustCompile(`^[0-9][0-9][0-9][.\-]?[0-9][0-9][0-9][0-9]$`) | |
var longPhone = regexp.MustCompile(`^[(]?[0-9][0-9][0-9][). \-]*[0-9][0-9][0-9][.\-]?[0-9][0-9][0-9][0-9]$`) | |
func main() { |
This file contains 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
// IPv4 | |
// | |
// Excluded ranges: | |
// 10.0.0.0/8 | |
// 172.16.0.0/12 | |
// 192.168.0.0/16 | |
// 100.64.0.0/10 | |
// 224.0.0.0/4 | |
// 240.0.0.0/4 | |
builder.addRoute("0.0.0.0", 5) |
This file contains 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 fs | |
import ( | |
"fmt" | |
"io" | |
"os" | |
. "io/fs" | |
) |
This file contains 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
// https://go2goplay.golang.org/p/MGkmOhAcV79 | |
package main | |
import ( | |
"fmt" | |
) | |
type Pair[K, V any] struct { | |
Key K |
NewerOlder