urban

package module
v0.0.0-...-9167b80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 9 Imported by: 1

README

Urban Go

Urban Dictionary API for Go (golang)

View the GoDoc

Install

$ go get github.com/pollen5/urban-go

Usage

package main

import (
  "fmt"
  "github.com/pollen5/urban-go"
)

func main() {
  entries, err := urban.Define("term")
  if err != nil {
    fmt.Println(err)
    return
  }
  for _, entry := range entries {
    fmt.Printf("Definition: %s\nExample: %s\nAuthor: %s",
      entry.Definition,
      entry.Example,
      entry.Author,
    )
  }
}
Markdown/HTML

A utility is provided to render a definition into markdown or html style

urban.Markdown("[some term]")
// => [some term](https://www.urbandictionary.com/define.php?term=some+term)
urban.HTML("[some term]")
// => <a href="https://www.urbandictionary.com/define.php?term=some+term">some term</a>

License

MIT

Documentation

Overview

Urban Go A Golang package to search urban dictionary.

Index

Constants

View Source
const Version = "0.0.2"

The version of the package.

Variables

View Source
var Regexp = regexp.MustCompile("\\[([^\\][]+)\\]")

The regexp used to match [] boxes

View Source
var WS = regexp.MustCompile("\\s+")

Regexp to replace whitespaces with +

Functions

func HTML

func HTML(str string) string

HTML renders a given string to HTML style. [some term] => <a href="https://www.urbandictionary.com/define.php?term=some+term">some term</a> str is also HTML-escaped

func Markdown

func Markdown(str string) string

Markdown renders a given string to Markdown style. [some term] => [some term](https://www.urbandictionary.com/define.php?term=some+term)

Types

type Entry

type Entry struct {
	Definition  string    `json:"definition"`
	Example     string    `json:"example"`
	Author      string    `json:"author"`
	Word        string    `json:"word"`
	DefID       int       `json:"defid"`
	PermaLink   string    `json:"permalink"`
	SoundURLs   []string  `json:"sound_urls"`
	ThumbsUp    int       `json:"thumbs_up"`
	ThumbsDown  int       `json:"thumbs_down"`
	CurrentVote string    `json:"current_vote"`
	WrittenOn   time.Time `json:"written_on"`
}

Entry represents an entry in the dictionary.

func Define

func Define(term string) ([]*Entry, error)

Define gets the definitions for a term.

func DefineByID

func DefineByID(defid int) ([]*Entry, error)

DefineByID returns definitions for a given defid

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL