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
// This example shows how to send files via pipe using multipart package | |
package main | |
import ( | |
"errors" | |
"fmt" | |
"io" | |
"mime/multipart" | |
"os" |
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
// Versiyon 2 | |
package main | |
import "fmt" | |
type Foo struct{} | |
func main() { | |
a := &Foo{} | |
b := &Foo{} |
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
// Versiyon 1 | |
package main | |
import "fmt" | |
type Foo struct{} | |
func main() { | |
a := &Foo{} | |
b := &Foo{} |
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
// Method 1 | |
struct User { | |
} | |
enum SecurityError: Error { | |
case emptyEmail | |
case emptyPassword | |
} |
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
// Usage | |
let logger = Logger("YakuterPackage.ViewController") | |
logger.info("Result: %{public}@", result) | |
logger.error("This is an error log") | |
// Logger.swift file content |
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
// 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)) | |
} |
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
// 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 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
src := []int{1, 2, 3, 4, 5} | |
dst := make([]int, 5) | |
// copy from slice to slice | |
copied := copy(dst, src) | |
// copied: 5 | |
// dst: [1 2 3 4 5] | |
// copy from string to slice | |
var b = make([]byte, 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 main | |
import "fmt" | |
func main() { | |
var s []int | |
// len=0 cap=0 [] | |
s = append(s, 0) // append works on nil slices. | |
// len=1 cap=1 [0] |
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" | |
"io" | |
"os" | |
) | |
func main() { | |
reader, writer := io.Pipe() |