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
| // Versiyon 1 | |
| package main | |
| import "fmt" | |
| type Foo struct{} | |
| func main() { | |
| a := &Foo{} | |
| b := &Foo{} |
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
| // This example shows how to send files via pipe using multipart package | |
| package main | |
| import ( | |
| "errors" | |
| "fmt" | |
| "io" | |
| "mime/multipart" | |
| "os" |
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
| # distro prints the detected operating system including linux distros. | |
| # Also parses ID_LIKE for common distro bases. | |
| # | |
| # Example outputs: | |
| # - macos -> macos | |
| # - freebsd -> freebsd | |
| # - ubuntu, raspbian, debian ... -> debian | |
| # - amzn, centos, rhel, fedora, ... -> fedora | |
| # - opensuse-{leap,tumbleweed} -> opensuse | |
| # - alpine -> alpine |
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
| # Private Keys and Certificates in this file generated with the commands below | |
| openssl genrsa 2048 > ca-key.pem | |
| openssl req -new -x509 -nodes -days 365000 \ | |
| -key ca-key.pem \ | |
| -out ca-cert.pem \ | |
| -addext "subjectAltName = IP:127.0.0.1" | |
| openssl req -newkey rsa:2048 -nodes -days 365000 \ |
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
| func main() { | |
| fs := token.NewFileSet() | |
| f, err := parser.ParseFile(fs, "", "package main\nvar x int = 9\nfunc main(){b:=2}", parser.AllErrors) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| var v visitor | |
| ast.Walk(v, f) | |
| //fmt.Printf("%#v",f) | |
| } |
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
| // +build windows | |
| package main | |
| import ( | |
| "crypto/x509" | |
| "fmt" | |
| "syscall" | |
| "unsafe" | |
| ) |
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
| type Args interface { | |
| // Get returns the nth argument, or else a blank string | |
| Get(n int) string | |
| // First returns the first argument, or else a blank string | |
| First() string | |
| // Tail returns the rest of the arguments (not the first one) | |
| // or else an empty string slice | |
| Tail() []string | |
| // Len returns the length of the wrapped slice | |
| Len() int |
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
| // Source: https://ixday.github.io/post/golang-cancel-copy/ | |
| import ( | |
| "io" | |
| "context" | |
| ) | |
| // here is some syntaxic sugar inspired by the Tomas Senart's video, | |
| // it allows me to inline the Reader interface | |
| type readerFunc func(p []byte) (n int, err error) |
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 ( | |
| "log" | |
| "os" | |
| ) | |
| func main() { | |
| file, err := os.OpenFile("geekday.txt", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) | |
| if err != nil { |
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
| // b2s converts byte slice to a string without memory allocation. | |
| // See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ . | |
| // | |
| // Note it may break if string and/or slice header will change | |
| // in the future go versions. | |
| func b2s(b []byte) string { | |
| /* #nosec G103 */ | |
| return *(*string)(unsafe.Pointer(&b)) | |
| } |