Skip to content

Instantly share code, notes, and snippets.

@foolishway
foolishway / goroutine channel
Created January 4, 2020 07:33
goroutine channel
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func main() {
@foolishway
foolishway / Errors_are_values
Created January 20, 2020 08:52
Errors are values, handle errors gracefully.
package main
import (
"io"
"log"
)
type Writter struct {
w io.Writer
e error
}
@foolishway
foolishway / crawler.go
Last active February 25, 2020 02:05
Fetch web blogs page by page and save the html content to local
package main
import (
"bytes"
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
package main
import (
"fmt"
"runtime"
"sync"
"time"
)
type ProductConsumer struct {
package main
import (
"encoding/json"
"fmt"
"time"
)
type MyUser struct {
ID int64 `json:"id"`
package main
import (
"log"
"net/http"
)
type handler func(w http.ResponseWriter, r *http.Request)
func decorator(ft handler) handler {
package main
import (
"fmt"
"sync"
"sync/atomic"
"time"
)
type work struct {
package main
import (
"fmt"
"math"
)
type Calculator struct {
acc float64
}
package main
import (
"fmt"
"strconv"
)
type Istring interface {
string(string) string
}
package main
import (
"fmt"
"unsafe"
)
func main() {
b := []byte("some momery")
s := string(b)