Skip to content

Commit

Permalink
Removed uuid dep
Browse files Browse the repository at this point in the history
  • Loading branch information
iDigitalFlame committed Dec 12, 2021
1 parent e9632d0 commit 79b4fb4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/PurpleSec/switchproxy

go 1.12

require github.com/google/uuid v1.1.1
go 1.17
2 changes: 0 additions & 2 deletions go.sum

This file was deleted.

25 changes: 20 additions & 5 deletions switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import (
"strings"
"time"

"github.com/google/uuid"
// Import unsafe to use "fastrand" function
_ "unsafe"
)

const table = "0123456789ABCDEF"

// Result is a struct that contains the data of the resulting Switch
// operation to be passed to Handlers.
type Result struct {
Expand Down Expand Up @@ -57,6 +60,20 @@ type Switch struct {
// Handler is a function alias that can be passed a Result for processing.
type Handler func(Result)

//go:linkname fastRand runtime.fastrand
func fastRand() uint32
func newUUID() string {
var b [64]byte
for i := 0; i < 64; i += 2 {
v := byte(fastRand() & 0xFF)
if v < 16 {
b[i], b[i+1] = '0', table[v&0x0F]
}
b[i], b[i+1] = table[v>>4], table[v&0x0F]
}
return string(b[:])
}

// IsResponse is a function that returns true if the Result is for a response.
func (r Result) IsResponse() bool {
return len(r.Method) > 0 && r.Status > 0
Expand Down Expand Up @@ -131,14 +148,12 @@ func (s Switch) process(x context.Context, r *http.Request, t *transfer) (int, h
if s.timeout > 0 {
x, f = context.WithTimeout(x, s.timeout)
}
var (
u = uuid.New().String()
q, err = http.NewRequestWithContext(x, r.Method, s.String(), t.in)
)
q, err := http.NewRequestWithContext(x, r.Method, s.String(), t.in)
if err != nil {
f()
return 0, nil, err
}
u := newUUID()
if s.Pre != nil {
s.Pre(Result{
IP: r.RemoteAddr,
Expand Down

0 comments on commit 79b4fb4

Please sign in to comment.