Skip to content

Commit aab2d04

Browse files
committed
refactor: replace relog with goutils for logging and update function names for consistency
1 parent a8b8efd commit aab2d04

File tree

7 files changed

+29
-168
lines changed

7 files changed

+29
-168
lines changed

ctlog.go

+10-20
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import (
1414
"sync"
1515
"time"
1616

17-
"github.com/root4loot/relog"
18-
)
19-
20-
var (
21-
log = relog.NewLogger("ctlog")
17+
"github.com/root4loot/goutils/log"
2218
)
2319

2420
type Runner struct {
@@ -28,7 +24,6 @@ type Runner struct {
2824
Visited map[string]bool // map of visited targets
2925
}
3026

31-
// Options contains options for the runner
3227
type Options struct {
3328
Concurrency int // number of concurrent requests
3429
Timeout int // timeout in seconds
@@ -58,7 +53,6 @@ type Result struct {
5853

5954
var seen map[string]bool // map of seen domains
6055

61-
// DefaultOptions returns default options
6256
func DefaultOptions() *Options {
6357
return &Options{
6458
Concurrency: 3,
@@ -70,12 +64,13 @@ func DefaultOptions() *Options {
7064
}
7165
}
7266

73-
// NewRunner returns a new runner
7467
func NewRunner() *Runner {
7568
options := DefaultOptions()
7669

70+
log.Init("ctlog")
71+
7772
if options.Verbose {
78-
log.SetLevel(relog.DebugLevel)
73+
log.SetLevel(log.DebugLevel)
7974
}
8075

8176
return &Runner{
@@ -93,8 +88,7 @@ func NewRunner() *Runner {
9388
}
9489
}
9590

96-
// Single runs ctlog against a single target and waits for results to be returned
97-
func Single(target string) (results []Result) {
91+
func Run(target string) (results []Result) {
9892
log.Debug("Running against single target: ", target)
9993

10094
r := NewRunner()
@@ -105,9 +99,7 @@ func Single(target string) (results []Result) {
10599
return
106100
}
107101

108-
// Multiple runs ctlog against multiple targets and waits for results to be returned
109-
// Allows for options to be optionally passed
110-
func Multiple(targets []string, options ...Options) (results [][]Result) {
102+
func RunMultiple(targets []string, options ...Options) (results [][]Result) {
111103
r := NewRunner()
112104

113105
if len(options) > 0 {
@@ -131,12 +123,10 @@ func Multiple(targets []string, options ...Options) (results [][]Result) {
131123
return
132124
}
133125

134-
// MultipleStream runs ctlog against multiple targets and streams results to Results channel
135-
func (r *Runner) MultipleStream(targets []string) {
126+
func (r *Runner) RunMultipleAsync(targets []string) {
136127
log.Debug("Running async against multiple targets")
137128
defer close(r.Results)
138129

139-
// limit concurrency to number of targets
140130
if r.Options.Concurrency > len(targets) {
141131
r.Options.Concurrency = len(targets)
142132
}
@@ -161,7 +151,7 @@ func (r *Runner) MultipleStream(targets []string) {
161151
}
162152
time.Sleep(time.Millisecond * 100) // make room for processing results
163153
}(target)
164-
time.Sleep(r.getDelay() * time.Millisecond) // delay between requests
154+
time.Sleep(r.getDelay() * time.Millisecond)
165155
}
166156
}
167157
wg.Wait()
@@ -177,7 +167,7 @@ func (r *Result) Domain() (domain string) {
177167
}
178168

179169
func (r *Runner) query(ctx context.Context, target string, client *http.Client) (results []Result) {
180-
log.Debug("Running query against: ", target)
170+
log.Debug("Running query against:", target)
181171

182172
endpoint := "https://crt.sh/?q=" + url.QueryEscape(target) + "&output=json"
183173
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
@@ -208,7 +198,7 @@ func (r *Runner) query(ctx context.Context, target string, client *http.Client)
208198
return nil
209199
}
210200
} else {
211-
log.Warningf("%v - %s", err.Error(), target)
201+
log.Warnf("%v - %s", err.Error(), target)
212202
return nil
213203
}
214204
} else {

examples/multiple/multiple.go

+2-19
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,15 @@ import (
77
)
88

99
func main() {
10-
// With default options
11-
multiple()
12-
13-
// With custom options
14-
multipleWithOptions(ctlog.Options{
10+
options := &ctlog.Options{
1511
Concurrency: 2,
1612
Timeout: 90,
1713
Delay: 2,
1814
DelayJitter: 1,
1915
UserAgent: "ctlog",
20-
})
21-
}
22-
23-
func multiple() {
24-
results := ctlog.Multiple([]string{"example.com", "Hackerone Inc"})
25-
for _, result := range results {
26-
for _, res := range result {
27-
if res.Domain() != "" {
28-
fmt.Println(res.Domain())
29-
}
30-
}
3116
}
32-
}
3317

34-
func multipleWithOptions(options ctlog.Options) {
35-
results := ctlog.Multiple([]string{"example.com", "Hackerone Inc"}, options)
18+
results := ctlog.RunMultiple([]string{"example.com", "Hackerone Inc"}, *options)
3619
for _, result := range results {
3720
for _, res := range result {
3821
if res.Domain() != "" {

examples/multipleStream/multipleStream.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ func main() {
3030
}
3131
}()
3232

33-
// run ctlog against targets
34-
runner.MultipleStream(targets)
33+
runner.RunMultipleAsync(targets)
3534
}

examples/single/single.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77
)
88

99
func main() {
10-
// run ctlog against single target
11-
results := ctlog.Single("example.com")
10+
results := ctlog.Run("example.com")
1211
for _, result := range results {
1312
if result.Domain() != "" {
1413
fmt.Println(result.Domain())

go.mod

+5-18
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,12 @@ module github.com/root4loot/ctlog
22

33
go 1.21.1
44

5-
require (
6-
github.com/projectdiscovery/gologger v1.1.8
7-
github.com/root4loot/relog v0.0.0-20231028174855-efc3b4a0e7bf
8-
)
5+
require github.com/root4loot/goutils v0.0.0-20240917123709-f56ba37b015b
96

107
require (
11-
github.com/dsnet/compress v0.0.1 // indirect
12-
github.com/golang/snappy v0.0.1 // indirect
13-
github.com/json-iterator/go v1.1.12 // indirect
14-
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
15-
github.com/mholt/archiver v3.1.1+incompatible // indirect
16-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
17-
github.com/modern-go/reflect2 v1.0.2 // indirect
18-
github.com/nwaples/rardecode v1.1.0 // indirect
19-
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
208
github.com/sirupsen/logrus v1.9.3 // indirect
21-
github.com/ulikunitz/xz v0.5.7 // indirect
22-
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
23-
golang.org/x/sys v0.13.0 // indirect
24-
golang.org/x/term v0.13.0 // indirect
25-
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
9+
golang.org/x/crypto v0.19.0 // indirect
10+
golang.org/x/sys v0.17.0 // indirect
11+
golang.org/x/term v0.17.0 // indirect
12+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
2613
)

go.sum

+10-54
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,24 @@
1-
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
21
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
32
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
43
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
6-
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
7-
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
8-
github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY=
9-
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
10-
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
11-
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
12-
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
13-
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
14-
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
15-
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
16-
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
17-
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
18-
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
19-
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
20-
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
21-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
22-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
23-
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
24-
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
25-
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
26-
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
27-
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
28-
github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
29-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
30-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
31-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
32-
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
33-
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
34-
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
35-
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
36-
github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A=
37-
github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
384
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
395
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
40-
github.com/projectdiscovery/gologger v1.1.8 h1:CFlCzGlqAhPqWIrAXBt1OVh5jkMs1qgoR/z4xhdzLNE=
41-
github.com/projectdiscovery/gologger v1.1.8/go.mod h1:bNyVaC1U/NpJtFkJltcesn01NR3K8Hg6RsLVce6yvrw=
42-
github.com/root4loot/relog v0.0.0-20231028174855-efc3b4a0e7bf h1:nBwfAtZ/Xl4BOoW3OTwQLUPcExkfTQ03oapV7I8NQ7o=
43-
github.com/root4loot/relog v0.0.0-20231028174855-efc3b4a0e7bf/go.mod h1:+JOEx1I7zEO7z4UoLKuV1WWqv+4QD8FgsgOiWJeFJis=
6+
github.com/root4loot/goutils v0.0.0-20240917123709-f56ba37b015b h1:gqRwINxdct4XIzEncy6PePGvt7bw4BSLc11RdGGCFx8=
7+
github.com/root4loot/goutils v0.0.0-20240917123709-f56ba37b015b/go.mod h1:QpKgqgwXZMtvOIG+dnZm3Gu7jvgPNEBVb4T+f1uPmac=
448
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
459
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
4610
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
47-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
48-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
4911
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
50-
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
51-
github.com/ulikunitz/xz v0.5.7 h1:YvTNdFzX6+W5m9msiYg/zpkSURPPtOlzbqYjrFn7Yt4=
52-
github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
53-
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
54-
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
12+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
13+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
14+
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
15+
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
5516
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
56-
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
57-
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
58-
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
59-
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
60-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
61-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
17+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
18+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
19+
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
20+
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
6221
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
63-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
64-
gopkg.in/djherbis/times.v1 v1.3.0 h1:uxMS4iMtH6Pwsxog094W0FYldiNnfY/xba00vq6C2+o=
65-
gopkg.in/djherbis/times.v1 v1.3.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
6622
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6723
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
6824
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/log/log.go

-53
This file was deleted.

0 commit comments

Comments
 (0)