Added http.Handler interface
This commit is contained in:
10
snowflake.go
10
snowflake.go
@@ -4,6 +4,7 @@ package snowflake
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -85,6 +86,15 @@ func (n *Node) Generate() (ID, error) {
|
||||
), nil
|
||||
}
|
||||
|
||||
func (n *Node) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id, err := n.Generate()
|
||||
if err != nil {
|
||||
http.Error(w, "Internal Error", 500)
|
||||
}
|
||||
fmt.Fprint(w, id)
|
||||
}
|
||||
|
||||
// Int64 returns an int64 of the snowflake ID
|
||||
func (f ID) Int64() int64 {
|
||||
return int64(f)
|
||||
|
||||
Reference in New Issue
Block a user