~evanj/wtf2

89dc92eef3f23c88e5d1a3cac51b606465a41095 — Evan M Jones 5 months ago f91719a
Feat(definition String method): Adding String() method definition to
                                remove brackets from urban dictionary
                                output.
1 files changed, 7 insertions(+), 1 deletions(-)

M main.go
M main.go => main.go +7 -1
@@ 9,6 9,7 @@ import (
	"net/http"
	"net/url"
	"os"
	"regexp"
	"strconv"
	"strings"
	"time"


@@ 35,6 36,11 @@ type definition struct {
	Definition string
}

func (d definition) String() string {
	re := regexp.MustCompile(`\[(.+?)\]`)
	return re.ReplaceAllString(d.Definition, `$1`)
}

func search(ctx context.Context, term string) (*definition, error) {
	query := url.Values{}
	query.Add("term", string(term))


@@ 121,7 127,7 @@ func main() {
					return err
				}

				ch <- fmt.Sprintf("\033[1m%s\033[0m:\n%s\n", strings.Title(term), res.Definition)
				ch <- fmt.Sprintf("\033[1m%s\033[0m:\n%s\n", strings.Title(term), res.String())
				return nil
			})
		}(term)