Skip to content

Commit

Permalink
hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
amalfra committed Mar 11, 2017
1 parent f084af9 commit be83492
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: all

fmt:
go fmt ./...

vet:
go vet ./...

build: fmt vet
25 changes: 25 additions & 0 deletions etag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package etag

import (
"crypto/sha1"
"encoding/hex"
"fmt"
)

func getHash(str string) string {
h := sha1.New()
h.Write([]byte(str))

return hex.EncodeToString(h.Sum(nil))
}

// Generate an Etag for given sring. Allows specifying whether to generate weak
// Etag or not as second parameter
func Generate(str string, weak bool) string {
tag := fmt.Sprintf("%d-%s", len(str), getHash(str))
if weak {
tag = "W/" + tag
}

return tag
}

0 comments on commit be83492

Please sign in to comment.