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() { | |
add := make(chan int) | |
sum := 0 | |
go func() { |
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
func (c *Cache) Set(i *Item) error { | |
var buf bytes.Buffer | |
enc := msgpack.NewEncoder(&buf) | |
err := enc.Encode(i) | |
if err != nil { | |
return err | |
} | |
err = c.client.Set(i.ID, buf.Bytes(), 0).Err() | |
if err != nil { | |
return err |
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
func (c *Cache) Get(id string) (*Item, error) { | |
b, err := c.client.Get(id).Bytes() | |
if err == nil || err != redis.Nil { | |
buf := bytes.NewBuffer(b) | |
dec := msgpack.NewDecoder(buf) | |
var i Item | |
err = dec.Decode(&i) | |
if err == nil { | |
return &i,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
type Cache struct { | |
Repository | |
} | |
func (c *Cache) Get(id string) (*Item, error) { | |
return c.Repository.Get(id) | |
} | |
func (c *Cache) Set(i *Item) error { | |
return c.Repository.Set(i) |
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 Item struct { | |
ID string | |
Val string | |
} | |
type Repository interface { | |
Get(id string) (*Item, error) | |
Set(*Item) error | |
Ping() bool | |
} |
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 ( | |
"log" | |
"net/http" | |
) | |
func LogMiddleware(next http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
log.Println(r.URL) |
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 {{.Models}} | |
{{$ilen := len .Imports}} | |
{{if gt $ilen 0}} | |
import ( | |
{{range .Imports}}"{{.}}"{{end}} | |
) | |
{{end}} | |
{{range .Tables}} |
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
#!/bin/bash | |
inotifywait -q -m -e close_write articles/*.re | | |
while read -r filename event; do | |
./build-in-docker.sh | |
done |
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
export const storeShape = PropTypes.shape({ | |
subscribe: PropTypes.func.isRequired, | |
dispatch: PropTypes.func.isRequired, | |
getState: PropTypes.func.isRequired | |
}) |
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
const reducer = (state = initialState, action) => { | |
switch (action.type) { | |
case UPDATE: | |
// update state | |
return newState; | |
default: | |
return state; | |
} | |
}; |
NewerOlder