~evanj/wtf2

9fbc49d1f234a80256203d2bebab1a37d6a1a4b1 — Evan M Jones 4 months ago 89dc92e
Feat(main.go): Remove flags from terms.
1 files changed, 14 insertions(+), 4 deletions(-)

M main.go
M main.go => main.go +14 -4
@@ 53,7 53,7 @@ func search(ctx context.Context, term string) (*definition, error) {
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("failed to execute request to server")
		return nil, fmt.Errorf("failed to execute request to server: %w", err)
	}

	defer resp.Body.Close()


@@ 66,7 66,7 @@ func search(ctx context.Context, term string) (*definition, error) {
	var data response
	if err := json.Unmarshal(bod, &data); err != nil {
		if strings.Contains(string(bod), "503 first byte timeout") {
			return nil, fmt.Errorf("urban dictionary barfed, 503 first byte timeout, Varnish cache server")
			return nil, fmt.Errorf("urban dictionary barfed: 503 first byte timeout: Varnish cache server")
		}
		return nil, fmt.Errorf("failed to read data from server")
	}


@@ 101,6 101,16 @@ func main() {
		return
	}

	words := []string{}
	for i := 0; i < len(args); i++ {
		item := args[i]
		if item == "-w" || item == "-t" {
			i++
			continue
		}
		words = append(words, item)
	}

	maxwidth, err := strconv.Atoi(*width)
	if err != nil {
		perror("failed to parse -w max width option: %w", err)


@@ 109,7 119,7 @@ func main() {
	}

	var eg errgroup.Group
	ch := make(chan string, len(args))
	ch := make(chan string, len(words))

	timeout, err := strconv.Atoi(*timeoutStr)
	if err != nil {


@@ 118,7 128,7 @@ func main() {

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(timeout))

	for _, term := range args {
	for _, term := range words {
		func(term string) {
			eg.Go(func() error {
				res, err := search(ctx, term)