Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: segmentio/ksuid
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.2
Choose a base ref
...
head repository: segmentio/ksuid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.3
Choose a head ref
  • 5 commits
  • 5 files changed
  • 5 contributors

Commits on Oct 3, 2018

  1. Copy the full SHA
    a39015a View commit details

Commits on Oct 18, 2018

  1. Use text/template for ksuid cmd (#38)

    html/template includes escaping which is inappropriate for this use.
    tmthrgd authored and achille-roussel committed Oct 18, 2018
    Copy the full SHA
    b85603c View commit details

Commits on Mar 12, 2019

  1. Fix function comments based on best practices from Effective Go (#39)

    Signed-off-by: CodeLingo Bot <bot@codelingo.io>
    CodeLingoTeam authored and achille-roussel committed Mar 12, 2019
    Copy the full SHA
    7d859c5 View commit details

Commits on Jun 23, 2019

  1. Add unittest for Timestamp method (#42)

    nghialt authored and Achille committed Jun 23, 2019
    Copy the full SHA
    9349bd0 View commit details

Commits on Jun 28, 2020

  1. add go.mod

    Achille Roussel committed Jun 28, 2020
    Copy the full SHA
    46ca471 View commit details
Showing with 21 additions and 4 deletions.
  1. +4 −0 base62.go
  2. +1 −1 cmd/ksuid/main.go
  3. +3 −0 go.mod
  4. +3 −3 ksuid.go
  5. +10 −0 ksuid_test.go
4 changes: 4 additions & 0 deletions base62.go
Original file line number Diff line number Diff line change
@@ -112,6 +112,10 @@ func fastDecodeBase62(dst []byte, src []byte) error {
const srcBase = 62
const dstBase = 4294967296

// This line helps BCE (Bounds Check Elimination).
// It may be safely removed.
_ = src[26]

parts := [27]byte{
base62Value(src[0]),
base62Value(src[1]),
2 changes: 1 addition & 1 deletion cmd/ksuid/main.go
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@ import (
"encoding/hex"
"flag"
"fmt"
"html/template"
"io"
"os"
"strings"
"text/template"
"time"

"github.com/segmentio/ksuid"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/segmentio/ksuid

go 1.12
6 changes: 3 additions & 3 deletions ksuid.go
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ func (i KSUID) Bytes() []byte {
return i[:]
}

// Returns true if this is a "nil" KSUID
// IsNil returns true if this is a "nil" KSUID
func (i KSUID) IsNil() bool {
return i == Nil
}
@@ -173,7 +173,7 @@ func (i *KSUID) scan(b []byte) error {
}
}

// Decodes a string-encoded representation of a KSUID object
// Parse decodes a string-encoded representation of a KSUID object
func Parse(s string) (KSUID, error) {
if len(s) != stringEncodedLength {
return Nil, errStrSize
@@ -285,7 +285,7 @@ func Sort(ids []KSUID) {
quickSort(ids, 0, len(ids)-1)
}

// Checks whether a slice of KSUIDs is sorted
// IsSorted checks whether a slice of KSUIDs is sorted
func IsSorted(ids []KSUID) bool {
if len(ids) != 0 {
min := ids[0]
10 changes: 10 additions & 0 deletions ksuid_test.go
Original file line number Diff line number Diff line change
@@ -304,6 +304,16 @@ func TestPrevNext(t *testing.T) {
}
}

func TestGetTimestamp(t *testing.T) {
nowTime := time.Now()
x, _ := NewRandomWithTime(nowTime)
xTime := int64(x.Timestamp())
unix := nowTime.Unix()
if xTime != unix - epochStamp {
t.Fatal(xTime, "!=", unix)
}
}

func testPrevNext(t *testing.T, id, prev, next KSUID) {
id1 := id.Prev()
id2 := id.Next()