-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this is an old project - commiting everything inside the folder
- Loading branch information
Lefteris Georgatos
committed
May 20, 2024
0 parents
commit bedbf5a
Showing
11 changed files
with
847 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
) | ||
|
||
// Counter Stores counts associated with a key. | ||
type Counter struct { | ||
m sync.Map | ||
} | ||
|
||
// Get Retrieves the count without modifying it | ||
func (c *Counter) Get(key string) (int64, bool) { | ||
count, ok := c.m.Load(key) | ||
if ok { | ||
return atomic.LoadInt64(count.(*int64)), true | ||
} | ||
return 0, false | ||
} | ||
|
||
// Add Adds value to the stored underlying value if it exists. | ||
// If it does not exists, the value is assigned to the key. | ||
func (c *Counter) Add(key string, value int64) int64 { | ||
count, loaded := c.m.LoadOrStore(key, &value) | ||
if loaded { | ||
return atomic.AddInt64(count.(*int64), value) | ||
} | ||
return *count.(*int64) | ||
} | ||
|
||
// DeleteAndGetLastValue Deletes the value associated with key and retrieves its. | ||
func (c *Counter) DeleteAndGetLastValue(key string) (int64, bool) { | ||
lastValue, loaded := c.m.LoadAndDelete(key) | ||
if loaded { | ||
return *lastValue.(*int64), loaded | ||
} | ||
|
||
return 0, false | ||
} |
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,24 @@ | ||
module redtest | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/schollz/progressbar/v3 v3.13.1 | ||
github.com/urfave/cli/v2 v2.25.1 | ||
) | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect | ||
github.com/mattn/go-runewidth v0.0.14 // indirect | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect | ||
github.com/rivo/uniseg v0.4.4 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 // indirect | ||
github.com/shurcooL/go-goon v1.0.0 // indirect | ||
github.com/shurcooL/goexec v0.0.0-20230709021537-96bada04ea2b // indirect | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect | ||
golang.org/x/mod v0.12.0 // indirect | ||
golang.org/x/sys v0.12.0 // indirect | ||
golang.org/x/term v0.7.0 // indirect | ||
golang.org/x/tools v0.13.0 // indirect | ||
) |
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,46 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= | ||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= | ||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= | ||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= | ||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE= | ||
github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ= | ||
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ= | ||
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= | ||
github.com/shurcooL/go-goon v1.0.0 h1:BCQPvxGkHHJ4WpBO4m/9FXbITVIsvAm/T66cCcCGI7E= | ||
github.com/shurcooL/go-goon v1.0.0/go.mod h1:2wTHMsGo7qnpmqA8ADYZtP4I1DD94JpXGQ3Dxq2YQ5w= | ||
github.com/shurcooL/goexec v0.0.0-20230709021537-96bada04ea2b h1:637/WtTYN6u1wzt0dCpGdBJHIggB8inZei6q60AZwjk= | ||
github.com/shurcooL/goexec v0.0.0-20230709021537-96bada04ea2b/go.mod h1:YrZDETqiwAqnKsivK9+sxwhS9rjMR+2NWGy8TATNb6k= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw= | ||
github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= | ||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= | ||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= | ||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= | ||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= | ||
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= | ||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= | ||
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= | ||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= |
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,18 @@ | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<script src="./wasm_exec.js"></script> | ||
<script> | ||
const go = new Go(); | ||
WebAssembly.instantiateStreaming(fetch("./main.wasm"), go.importObject).then((result) => { | ||
go.run(result.instance); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
asd | ||
</body> | ||
|
||
</html> |
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,140 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
"io" | ||
"math/rand" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/schollz/progressbar/v3" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var counter Counter | ||
|
||
type UrlSet struct { | ||
XMLName xml.Name `xml:"urlset"` | ||
Urls []Url `xml:"url"` | ||
} | ||
type Url struct { | ||
Loc string `xml:"loc"` | ||
NewLoc string | ||
} | ||
|
||
func makeRequest(url string, wg *sync.WaitGroup, bar *progressbar.ProgressBar) { | ||
client := http.Client{} | ||
response, err := client.Get(url) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
defer func() { | ||
respBodyClose := response.Body.Close() | ||
if respBodyClose != nil { | ||
fmt.Print(respBodyClose.Error()) | ||
|
||
return | ||
} | ||
}() | ||
|
||
barError := bar.Add(1) | ||
if barError != nil { | ||
fmt.Printf(barError.Error()) | ||
} | ||
|
||
defer wg.Done() | ||
counter.Add(response.Status, 1) | ||
} | ||
|
||
func getXmlFromUrl(xmlUrl string) []byte { | ||
resp, getErr := http.Get(xmlUrl) | ||
if getErr != nil { | ||
fmt.Printf(getErr.Error()) | ||
} | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
|
||
defer func() { | ||
respErr := resp.Body.Close() | ||
if respErr != nil { | ||
fmt.Printf(respErr.Error()) | ||
} | ||
}() | ||
|
||
if err != nil { | ||
fmt.Printf(err.Error()) | ||
} | ||
return body | ||
} | ||
|
||
func printSyncMap(counter *Counter) { | ||
i := 0 | ||
counter.m.Range(func(key, value interface{}) bool { | ||
int64val, _ := counter.Get(key.(string)) | ||
|
||
fmt.Printf("\t[%d] key: %v, value: %d\n", i, key, int64val) | ||
i++ | ||
return true | ||
}) | ||
} | ||
|
||
func start(url string) { | ||
bar := progressbar.NewOptions(-1, | ||
progressbar.OptionEnableColorCodes(true), | ||
progressbar.OptionSetPredictTime(true), | ||
progressbar.OptionShowIts(), | ||
progressbar.OptionShowCount(), | ||
progressbar.OptionClearOnFinish(), | ||
progressbar.OptionSetDescription("[yellow]Trying redirects...[reset]")) | ||
|
||
data := getXmlFromUrl(url) | ||
var urlSet UrlSet | ||
var wg sync.WaitGroup | ||
|
||
defer func() { | ||
finishError := bar.Finish() | ||
println(fmt.Errorf(finishError.Error())) | ||
}() | ||
|
||
unmarshalErr := xml.Unmarshal(data, &urlSet) | ||
if unmarshalErr != nil { | ||
fmt.Printf(unmarshalErr.Error()) | ||
} | ||
|
||
for _, v := range urlSet.Urls { | ||
r := rand.Intn(1000000) | ||
time.Sleep(time.Duration(r) * time.Microsecond) | ||
|
||
url := strings.Replace(v.Loc, "watch", "oroloi", -1) | ||
v.NewLoc = url | ||
wg.Add(1) | ||
|
||
go makeRequest(url, &wg, bar) | ||
} | ||
|
||
wg.Wait() | ||
|
||
printSyncMap(&counter) | ||
} | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "redtest", | ||
Usage: "testing redirects", | ||
Action: func(cCtx *cli.Context) error { | ||
fmt.Printf("Running for %s\n", cCtx.Args().Get(0)) | ||
start(cCtx.Args().Get(0)) | ||
return nil | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
|
||
if err != nil { | ||
fmt.Printf(err.Error()) | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.