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
| docker rm $(docker ps -a -q) | |
| docker rmi $(docker images -q) | |
| docker volume rm $(docker volume ls |awk '{print $2}') | |
| STOP DOCKER | |
| rm -rf ~/Library/Containers/com.docker.docker/Data/* |
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 security | |
| import ( | |
| "crypto/rand" | |
| "crypto/rsa" | |
| "crypto/x509" | |
| "encoding/pem" | |
| "github.com/pkg/errors" | |
| ) |
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 GenerateToken(signingKey []byte, clientID string, id string, lifeDur time.Duration) (*Token, error) { | |
| var expiredAt time.Time | |
| if id != "" { | |
| expiredAt = time.Now().Add(defaultRefreshExp) | |
| } else { | |
| expiredAt = time.Now().Add(lifeDur) | |
| } | |
| claims := CustomClaims{ | |
| clientID, | |
| jwt.StandardClaims{ |
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 HashPassword(password string) (string, error) { | |
| bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) | |
| return string(bytes), err | |
| } | |
| func CheckPasswordHash(password, hash string) bool { | |
| err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) | |
| return 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
| type Encoder struct { | |
| Block cipher.Block | |
| SecretKey string | |
| } | |
| func (e *Encoder) Encode(message string) (string, error) { | |
| plainText := []byte(message) | |
| cipherText := make([]byte, aes.BlockSize+len(plainText)) | |
| iv := cipherText[:aes.BlockSize] | |
| if _, err := io.ReadFull(rand.Reader, iv); 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
| ype Scheduler struct { | |
| interval time.Duration | |
| } | |
| func (s *Scheduler) Run() { | |
| go func() { | |
| for { | |
| select { | |
| case <-timeutil.After(s.interval): | |
| s.process() |
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
| resp, err := http.Get(s.host) | |
| if err != nil { | |
| return err | |
| } | |
| defer resp.Body.Close() | |
| scanner := bufio.NewScanner(resp.Body) | |
| for scanner.Scan() { | |
| fmt.Println(scanner.Text()) | |
| } |
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
| // After it also works as a "time.After" but it does truncate by duration. | |
| func After(d time.Duration) <-chan time.Time { | |
| return time.After(time.Until(time.Now().Truncate(d).Add(d))) | |
| } |
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
| const DefaultTolerance = 4 | |
| func (m Message) Distance(e bktree.Entry) int { | |
| return levenshtein.Distance(m.Name, e.(Message).Name) | |
| } | |
| type Searcher struct { | |
| tree bktree.BKTree | |
| } |
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
| cat certfile.crt bundle.ca-bundle >> chain.crt |
NewerOlder