-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename request-id in correlation-id (#19)
* rename request-id in correlation-id * fixup tripperware correlation from req.context
- Loading branch information
1 parent
3c74fbd
commit ae8a6b4
Showing
12 changed files
with
151 additions
and
123 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package correlation_id | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
const HeaderName = "Correlation-Id" | ||
|
||
type Config struct { | ||
HeaderName string | ||
IdGenerator func(*http.Request) string | ||
} | ||
|
||
func NewConfig() *Config { | ||
return &Config{ | ||
HeaderName: HeaderName, | ||
IdGenerator: func(_ *http.Request) string { | ||
return DefaultIdGenerator.Generate(10) | ||
}, | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package correlation_id_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/gol4ng/httpware/correlation_id" | ||
) | ||
|
||
func TestNewConfig(t *testing.T) { | ||
defaultRand := rand.New(correlation_id.NewLockedSource(rand.NewSource(1))) | ||
correlation_id.DefaultIdGenerator = correlation_id.NewRandomIdGenerator(defaultRand) | ||
|
||
for _, expectedId := range []string{"p1LGIehp1s", "uqtCDMLxiD"} { | ||
assert.Equal(t, expectedId, correlation_id.NewConfig().IdGenerator(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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package correlation_id_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/gol4ng/httpware/correlation_id" | ||
) | ||
|
||
func Test_Random(t *testing.T) { | ||
assert.Equal(t, 10, len(correlation_id.DefaultIdGenerator.Generate(10))) | ||
} | ||
|
||
func Test_Random_NewSource(t *testing.T) { | ||
r := rand.New(correlation_id.NewLockedSource(rand.NewSource(1))) | ||
rg := correlation_id.NewRandomIdGenerator(r) | ||
for _, expectedId := range []string{"DHIMG9FpXzp1LGIehp1s", "zAHyfjXUlrGhblT7txWd"} { | ||
assert.Equal(t, expectedId, rg.Generate(20)) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package request_id | ||
package correlation_id | ||
|
||
import ( | ||
"math/rand" | ||
|
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.