Premier commit
This commit is contained in:
40
cmd/cli/main.go
Normal file
40
cmd/cli/main.go
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/foxdeveloper/namecheck"
|
||||
_ "github.com/foxdeveloper/namecheck/github"
|
||||
_ "github.com/foxdeveloper/namecheck/twitter"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
ch := make(chan string)
|
||||
start := time.Now()
|
||||
argsUsername := os.Args[1]
|
||||
|
||||
//go namecheck.Run(namecheck.SocialNetworks(), argsUsername, ch)
|
||||
for _, sn := range namecheck.SocialNetworks() {
|
||||
wg.Add(1)
|
||||
go func(sn namecheck.SocialNetwork) {
|
||||
namecheck.Namecheck(sn, argsUsername, &wg, ch)
|
||||
}(sn)
|
||||
}
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
for v := range ch {
|
||||
fmt.Printf("%s", v)
|
||||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("Took %s", elapsed)
|
||||
}
|
43
cmd/server/main.go
Normal file
43
cmd/server/main.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/foxdeveloper/namecheck"
|
||||
_ "github.com/foxdeveloper/namecheck/github"
|
||||
_ "github.com/foxdeveloper/namecheck/twitter"
|
||||
)
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
var wg sync.WaitGroup
|
||||
ch := make(chan string)
|
||||
for _, sn := range namecheck.SocialNetworks() {
|
||||
wg.Add(1)
|
||||
go func(sn namecheck.SocialNetwork) {
|
||||
namecheck.Namecheck(sn, r.URL.Path[1:], &wg, ch)
|
||||
}(sn)
|
||||
}
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
for v := range ch {
|
||||
fmt.Fprintf(w, "%s", v)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
start := time.Now()
|
||||
|
||||
http.HandleFunc("/", handler)
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("Took %s", elapsed)
|
||||
}
|
39
cmd/test/main.go
Normal file
39
cmd/test/main.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func prepareSouffle() {
|
||||
fmt.Println("Je prépare un souffle")
|
||||
}
|
||||
|
||||
func preparePatatoes() {
|
||||
fmt.Println("Je prépare des patates")
|
||||
}
|
||||
|
||||
func printTenIntsConcurrently(ch chan int) {
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go printInt(i, &wg, &ch)
|
||||
}
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
}
|
||||
|
||||
func printInt(i int, wg *sync.WaitGroup, ch *chan int) {
|
||||
defer wg.Done()
|
||||
*ch <- i
|
||||
}
|
||||
|
||||
func main() {
|
||||
ints := make(chan int)
|
||||
|
||||
go printTenIntsConcurrently(ints)
|
||||
|
||||
for i := range ints {
|
||||
fmt.Printf("%d\n", i)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user