Mongo cdn getter (#62)

* Implementing a MongoDB backed CDN getter

Fixes https://github.com/gomods/athens/issues/49

* removing the base URL from the CDN getter
This commit is contained in:
Aaron Schlesinger
2018-03-23 13:41:22 -07:00
committed by GitHub
parent a70ca0564c
commit b7e15a845c
19 changed files with 1589 additions and 6 deletions
Generated
+7 -1
View File
@@ -498,6 +498,12 @@
revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71"
version = "v1.2.1"
[[projects]]
name = "github.com/technosophos/moniker"
packages = ["."]
revision = "4d1d2a7d4b69cee56dadb6a7634945f829154858"
version = "0.1.0"
[[projects]]
branch = "master"
name = "github.com/unrolled/secure"
@@ -585,6 +591,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "3a98ca2d38e280de54c478d732fbd7bf639d854ffab742a3509fbad2a9b86594"
inputs-digest = "175a70f01383e4767dfbbed2704602d7205fa8dc5fac2c32a1c188fa65090db0"
solver-name = "gps-cdcl"
solver-version = 1
+1 -1
View File
@@ -27,7 +27,7 @@ func goGetMeta(c buffalo.Context, getter cdn.Getter) error {
if err != nil {
return err
}
loc, err := getter.Get(params.module, params.version)
loc, err := getter.Get(params.module)
if err != nil {
return c.Error(http.StatusNotFound, fmt.Errorf("module %s does not exist", params.module))
}
+3 -2
View File
@@ -8,10 +8,11 @@ development:
test:
dialect: "mysql"
database: circle-test
database: vgoprox
host: 127.0.0.1
port: 3306
user: ubuntu
user: vgp
password: vgp
production:
dialect: "mysql"
+9
View File
@@ -4,3 +4,12 @@ services:
image: mongo:3.0.15-wheezy
ports:
- 27017:27017
mysql:
image: bitnami/mysql:5.7.21-r7
ports:
- "3306:3306"
environment:
- "ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_USER=vgp"
- "MYSQL_PASSWORD=vgp"
- "MYSQL_DATABASE=vgoprox"
+40
View File
@@ -0,0 +1,40 @@
-- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64)
--
-- Host: 127.0.0.1 Database: vgoprox
-- ------------------------------------------------------
-- Server version 5.7.21
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `schema_migration`
--
DROP TABLE IF EXISTS `schema_migration`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `schema_migration` (
`version` varchar(255) NOT NULL,
UNIQUE KEY `version_idx` (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2018-03-21 16:06:17
+1 -1
View File
@@ -6,6 +6,6 @@ type Getter struct {
}
// Get is the cdn.Getter implementation that always returns g.URL, nil
func (g *Getter) Get(baseURL, module string) (string, error) {
func (g *Getter) Get(module string) (string, error) {
return g.URL, nil
}
+1 -1
View File
@@ -12,5 +12,5 @@ package cdn
// - https://mycdn.com/gomods.io/my/module/@v/{version}.mod
// - https://mycdn.com/gomods.io/my/module/@v/{version}.zip
type Getter interface {
Get(baseURL, module string) (string, error)
Get(module string) (string, error)
}
+9
View File
@@ -0,0 +1,9 @@
package mongo
// Entry is stored in the DB. Right now it just holds a redirect URL to
// the CDN
type Entry struct {
Module string `bson:"module"`
RedirectURL string `bson:"redirect_url"`
// Other fields?
}
+22
View File
@@ -0,0 +1,22 @@
package mongo
import (
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)
type getter struct {
conn *mgo.Session
db string
coll string
}
func (g *getter) Get(module string) (string, error) {
coll := g.conn.DB(g.db).C(g.coll)
params := bson.M{"module": module}
entry := Entry{}
if err := coll.Find(params).One(&entry); err != nil {
return "", nil
}
return entry.RedirectURL, nil
}
+19
View File
@@ -0,0 +1,19 @@
package mongo
import (
"testing"
"github.com/gomods/athens/pkg/fixtures"
"github.com/stretchr/testify/suite"
)
type MongoTests struct {
*fixtures.Mongo
}
func RunMongoTests(t *testing.T) {
suite.Run(t, &MongoTests{Mongo: fixtures.NewMongo(fixtures.DefaultMongoURL)})
}
// TODO: add round-trip tests when a mongo saver is done
// (https://github.com/gomods/athens/issues/50)
+55
View File
@@ -0,0 +1,55 @@
package fixtures
import (
"github.com/globalsign/mgo"
"github.com/stretchr/testify/suite"
"github.com/technosophos/moniker"
)
var names = moniker.NewAlliterator()
// DefaultMongoURL is the default Mongo URL for testing
const DefaultMongoURL = "127.0.0.1:27017"
// Mongo is a text fixture for use with github.com/stretchr/testify/suite tests
//
// use it like this:
//
// type MyTests struct {
// *fixtures.Mongo
// }
//
// func RunMyTests(t *testing.T) {
// suite.Run(t, &MyTests{Mongo: New(DefaultURL)})
// }
type Mongo struct {
suite.Suite
url string
dbName string
DB *mgo.Database
}
// SetupTest creates a new mongo connection and DB, and attaches it to a
// session before each test executes
//
// This implements the SetupTestSuite interface
func (m *Mongo) SetupTest() {
sess, err := mgo.Dial(m.url)
m.Require().NoError(err)
m.DB = sess.DB(m.dbName)
}
// TearDownTest drops the database that was created in SetupTest
//
// This implements the TearDownTestSuite interface
func (m *Mongo) TearDownTest() {
m.Require().NoError(m.DB.DropDatabase())
}
// NewMongo creates a new Mongo test fixture
func NewMongo(url string) *Mongo {
return &Mongo{
url: url,
dbName: names.NameSep("-") + "-athens-testing",
}
}
+20
View File
@@ -0,0 +1,20 @@
Moniker
Copyright (C) 2016, Matt Butcher
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+52
View File
@@ -0,0 +1,52 @@
# Monicker: Generate Cute Random Names
Monicker is a tiny Go library for automatically naming things.
```console
$ for i in [ 1 2 3 4 5 ]; do go run _example/namer.go; done
Your name is "eating iguana"
Your name is "old whale"
Your name is "wrinkled lion"
Your name is "wintering skunk"
Your name is "kneeling giraffe"
Your name is "icy hummingbird"
Your name is "wizened guppy"
```
## Library Usage
Easily use Monicker in your code. Here's the complete code behind the
tool above:
```go
package main
import (
"fmt"
"github.com/technosophos/moniker"
)
func main() {
n := moniker.New()
fmt.Printf("Your name is %q\n", n.Name())
}
```
Since Monicker compiles the name list into the application, there's no
requirement that your app has supporting files.
## Customizing the Words
Monicker ships with a couple of word lists that were written and
approved by a group of giggling school children (and their dad). We
built a lighthearted list based on animals and descriptive words (mostly
adjectives).
First, we welcome contributions to our list. Note that we currate the
list to avoid things that might be offensive. (And if you get an
offensive pairing, please open an issue!)
Second, we wanted to make it easy for you to modify or build your own
wordlist. The script in `_generator` can take word lists and convert
them to Go code that Monicker understands.
+247
View File
@@ -0,0 +1,247 @@
aardvark
albatross
alligator
alpaca
anaconda
angelfish
ant
anteater
antelope
antelope
arachnid
armadillo
badger
blackbird
bat
bear
bee
beetle
billygoat
bird
bison
bobcat
boxer
bronco
buffalo
buffoon
bumblebee
bunny
butterfly
camel
cardinal
cat
clam
catfish
cheetah
chicken
chimp
chinchilla
chipmunk
clownfish
condor
coral
cow
crab
cricket
crocodile
deer
dingo
dog
donkey
dragon
dragonfly
duck
eagle
echidna
eel
elephant
elk
emu
ferrit
fish
flee
fly
fox
frog
garfish
gecko
gibbon
giraffe
goat
goose
gorilla
greyhound
grasshopper
grizzly
guppy
hare
hamster
heron
hog
horse
hound
hydra
hyena
hummingbird
ibis
ibex
iguana
indri
jackal
joey
jaguar
jellyfish
kangaroo
kiwi
kitten
koala
kudu
labradoodle
ladybird
ladybug
lamb
lambkin
lion
lizzard
lionfish
liger
lightningbug
llama
leopard
lemur
lobster
lynx
marmot
manatee
marsupial
macaw
mandrill
marsupial
magpie
markhor
mastiff
maltese
mink
meerkat
mole
molly
mongoose
manta
stoat
monkey
moose
moth
mule
mouse
narwhal
newt
nightingale
numbat
orangutan
ocelot
ostrich
otter
oyster
octopus
olm
owl
opossum
parrot
panther
peacock
peahen
pika
penguin
pig
pike
platypus
poodle
pronghorn
panda
pug
prawn
puma
porcupine
possum
puffin
rabbit
racoon
ragdoll
rat
rattlesnake
robin
rodent
rottweiler
sabertooth
salamander
saola
scorpion
squid
seagull
seahorse
seal
sheep
shrimp
snake
serval
squirrel
sparrow
skunk
sasquatch
sloth
snail
stingray
swan
seastar
starfish
sponge
squid
shark
tapir
tarsier
termite
mite
gnat
tiger
toad
tortoise
toucan
turtle
turkey
tuatara
unicorn
uakari
umbrellabird
vulture
warthog
wallaby
walrus
otter
warthog
worm
wasp
waterbuffalo
whale
dolphin
fish
whippet
terrier
spaniel
greyhound
dachshund
wolf
wolverine
wombat
wildebeest
woodpecker
yak
zebra
zebu
zorse
quetzal
quail
quoll
quokka
gopher
hedgehog
gerbil
+252
View File
@@ -0,0 +1,252 @@
package moniker
// Animals is a generated list of words.
var Animals = []string{
"aardvark",
"albatross",
"alligator",
"alpaca",
"anaconda",
"angelfish",
"ant",
"anteater",
"antelope",
"antelope",
"arachnid",
"armadillo",
"badger",
"blackbird",
"bat",
"bear",
"bee",
"beetle",
"billygoat",
"bird",
"bison",
"bobcat",
"boxer",
"bronco",
"buffalo",
"buffoon",
"bumblebee",
"bunny",
"butterfly",
"camel",
"cardinal",
"cat",
"clam",
"catfish",
"cheetah",
"chicken",
"chimp",
"chinchilla",
"chipmunk",
"clownfish",
"condor",
"coral",
"cow",
"crab",
"cricket",
"crocodile",
"deer",
"dingo",
"dog",
"donkey",
"dragon",
"dragonfly",
"duck",
"eagle",
"echidna",
"eel",
"elephant",
"elk",
"emu",
"ferrit",
"fish",
"flee",
"fly",
"fox",
"frog",
"garfish",
"gecko",
"gibbon",
"giraffe",
"goat",
"goose",
"gorilla",
"greyhound",
"grasshopper",
"grizzly",
"guppy",
"hare",
"hamster",
"heron",
"hog",
"horse",
"hound",
"hydra",
"hyena",
"hummingbird",
"ibis",
"ibex",
"iguana",
"indri",
"jackal",
"joey",
"jaguar",
"jellyfish",
"kangaroo",
"kiwi",
"kitten",
"koala",
"kudu",
"labradoodle",
"ladybird",
"ladybug",
"lamb",
"lambkin",
"lion",
"lizzard",
"lionfish",
"liger",
"lightningbug",
"llama",
"leopard",
"lemur",
"lobster",
"lynx",
"marmot",
"manatee",
"marsupial",
"macaw",
"mandrill",
"marsupial",
"magpie",
"markhor",
"mastiff",
"maltese",
"mink",
"meerkat",
"mole",
"molly",
"mongoose",
"manta",
"stoat",
"monkey",
"moose",
"moth",
"mule",
"mouse",
"narwhal",
"newt",
"nightingale",
"numbat",
"orangutan",
"ocelot",
"ostrich",
"otter",
"oyster",
"octopus",
"olm",
"owl",
"opossum",
"parrot",
"panther",
"peacock",
"peahen",
"pika",
"penguin",
"pig",
"pike",
"platypus",
"poodle",
"pronghorn",
"panda",
"pug",
"prawn",
"puma",
"porcupine",
"possum",
"puffin",
"rabbit",
"racoon",
"ragdoll",
"rat",
"rattlesnake",
"robin",
"rodent",
"rottweiler",
"sabertooth",
"salamander",
"saola",
"scorpion",
"squid",
"seagull",
"seahorse",
"seal",
"sheep",
"shrimp",
"snake",
"serval",
"squirrel",
"sparrow",
"skunk",
"sasquatch",
"sloth",
"snail",
"stingeray",
"swan",
"seastar",
"starfish",
"sponge",
"squid",
"shark",
"tapir",
"tarsier",
"termite",
"mite",
"gnat",
"tiger",
"toad",
"tortoise",
"toucan",
"turtle",
"turkey",
"tuatara",
"unicorn",
"uakari",
"umbrellabird",
"vulture",
"warthog",
"wallaby",
"walrus",
"otter",
"warthog",
"worm",
"wasp",
"waterbuffalo",
"whale",
"dolphin",
"fish",
"whippet",
"terrier",
"spaniel",
"greyhound",
"dachshund",
"wolf",
"wolverine",
"wombat",
"wildebeest",
"woodpecker",
"yak",
"zebra",
"zebu",
"zorse",
"quetzal",
"quail",
"quoll",
"quokka",
"gopher",
"hedgehog",
"gerbil",
}
+389
View File
@@ -0,0 +1,389 @@
affable
aged
agile
alert
alliterating
altered
alternating
amber
angry
anxious
ardent
aspiring
austere
auxilliary
awesome
bailing
bald
banking
belligerent
bilging
billowing
binging
boiling
boisterous
bold
braided
brawny
brazen
broken
brown
bumptious
bunking
busted
calling
callous
cantankerous
cautious
calico
cloying
clunky
coiled
coiling
cold
contrasting
coy
crabby
cranky
crazy
crusty
dandy
dangling
dapper
deadly
dealing
dining
dinky
doltish
donating
dozing
dull
dunking
dusty
eager
early
eating
edgy
eerie
elder
elegant
elevated
eloping
enervated
eponymous
errant
erstwhile
esteemed
estranged
exacerbated
exasperated
excited
exciting
exegetical
exhaling
exiled
existing
eyewitness
factual
fair
fallacious
falling
famous
fancy
fantastic
fashionable
filled
flabby
flailing
flippant
foiled
foolhardy
foolish
foppish
full
fun
funky
funny
fuzzy
gangly
garish
gauche
gaudy
geared
giddy
giggly
gone
good
goodly
guiding
guilded
halting
handy
happy
hardy
harping
hasty
hazy
hipster
hissing
historical
honest
honking
honorary
hoping
hopping
iced
icy
ideal
idle
idolized
ignoble
ignorant
ill
illmannered
illocutionary
imprecise
impressive
incindiary
inclined
independent
inky
innocent
insipid
intended
intent
intentional
interested
interesting
invinvible
invisible
invited
iron
ironic
irreverant
jaundiced
jaunty
jazzed
jazzy
jittery
joking
jolly
joyous
juiced
jumpy
khaki
killer
killjoy
kilted
kind
kindled
kindly
kindred
kissable
kissed
kissing
kneeling
knobby
knotted
lame
lanky
laughing
lazy
left
limping
linting
listening
listless
littering
loitering
lolling
looming
looping
loopy
loping
lopsided
lovely
lucky
lumbering
luminous
lumpy
lunging
manageable
mangy
masked
maudlin
mean
measly
melting
messy
mewing
misty
modest
moldy
mollified
morbid
mortal
mothy
mottled
mouthy
muddled
musty
named
nasal
needled
newbie
nihilist
nobby
nomadic
nonexistent
nonplussed
nordic
nosy
nuanced
odd
oily
old
oldfashioned
olfactory
open
operatic
opining
opinionated
oppulent
orange
orbiting
ordered
orderly
original
ornery
peddling
peeking
pilfering
pining
pioneering
piquant
plinking
plucking
plundering
pondering
ponderous
pouring
precise
prodding
pruning
pugnacious
punk
quaffing
quarreling
quarrelsome
queenly
quelling
quiet
quieting
quoting
rafting
ranting
reeling
right
righteous
ringed
riotous
roiling
rolling
romping
rousing
rude
running
sad
sanguine
sappy
sartorial
saucy
silly
singed
singing
smelly
snug
soft
solemn
solid
solitary
steely
stultified
sullen
sweet
tailored
tan
telling
terrific
terrifying
tinseled
toned
torpid
torrid
trendsetting
trendy
triangular
truculent
tufted
turbulent
ugly
ulterior
undercooked
understood
ungaged
unhinged
unrealistic
unrealized
unsung
veering
vehement
vested
vetoed
viable
vigilant
virtuous
virulent
vocal
vociferous
volted
voting
wandering
wanton
warped
washed
washing
waxen
wayfaring
whimsical
wistful
whopping
wiggly
willing
winning
winsome
wintering
wise
wishful
wishing
wizened
wobbling
wobbly
womping
wonderful
wondering
worn
wrapping
wrinkled
xrayed
yellow
yodeling
youngling
your
youthful
yucky
yummy
zealous
zeroed
zinc
zooming
+394
View File
@@ -0,0 +1,394 @@
package moniker
// Descriptors is a generated list of words.
var Descriptors = []string{
"affable",
"aged",
"agile",
"alert",
"alliterating",
"altered",
"alternating",
"amber",
"angry",
"anxious",
"ardent",
"aspiring",
"austere",
"auxilliary",
"awesome",
"bailing",
"bald",
"banking",
"belligerent",
"bilging",
"billowing",
"binging",
"boiling",
"boisterous",
"bold",
"braided",
"brawny",
"brazen",
"broken",
"brown",
"bumptious",
"bunking",
"busted",
"calling",
"callous",
"cantankerous",
"cautious",
"calico",
"cloying",
"clunky",
"coiled",
"coiling",
"cold",
"contrasting",
"coy",
"crabby",
"cranky",
"crazy",
"crusty",
"dandy",
"dangling",
"dapper",
"deadly",
"dealing",
"dining",
"dinky",
"doltish",
"donating",
"dozing",
"dull",
"dunking",
"dusty",
"eager",
"early",
"eating",
"edgy",
"eerie",
"elder",
"elegant",
"elevated",
"eloping",
"enervated",
"eponymous",
"errant",
"erstwhile",
"esteemed",
"estranged",
"exacerbated",
"exasperated",
"excited",
"exciting",
"exegetical",
"exhaling",
"exiled",
"existing",
"eyewitness",
"factual",
"fair",
"fallacious",
"falling",
"famous",
"fancy",
"fantastic",
"fashionable",
"filled",
"flabby",
"flailing",
"flippant",
"foiled",
"foolhardy",
"foolish",
"foppish",
"full",
"fun",
"funky",
"funny",
"fuzzy",
"gangly",
"garish",
"gauche",
"gaudy",
"geared",
"giddy",
"giggly",
"gone",
"good",
"goodly",
"guiding",
"guilded",
"halting",
"handy",
"happy",
"hardy",
"harping",
"hasty",
"hazy",
"hipster",
"hissing",
"historical",
"honest",
"honking",
"honorary",
"hoping",
"hopping",
"iced",
"icy",
"ideal",
"idle",
"idolized",
"ignoble",
"ignorant",
"ill",
"illmannered",
"illocutionary",
"imprecise",
"impressive",
"incindiary",
"inclined",
"independent",
"inky",
"innocent",
"insipid",
"intended",
"intent",
"intentional",
"interested",
"interesting",
"invinvible",
"invisible",
"invited",
"iron",
"ironic",
"irreverant",
"jaundiced",
"jaunty",
"jazzed",
"jazzy",
"jittery",
"joking",
"jolly",
"joyous",
"juiced",
"jumpy",
"khaki",
"killer",
"killjoy",
"kilted",
"kind",
"kindled",
"kindly",
"kindred",
"kissable",
"kissed",
"kissing",
"kneeling",
"knobby",
"knotted",
"lame",
"lanky",
"laughing",
"lazy",
"left",
"limping",
"linting",
"listening",
"listless",
"littering",
"loitering",
"lolling",
"looming",
"looping",
"loopy",
"loping",
"lopsided",
"lovely",
"lucky",
"lumbering",
"luminous",
"lumpy",
"lunging",
"manageable",
"mangy",
"masked",
"maudlin",
"mean",
"measly",
"melting",
"messy",
"mewing",
"misty",
"modest",
"moldy",
"mollified",
"morbid",
"mortal",
"mothy",
"mottled",
"mouthy",
"muddled",
"musty",
"named",
"nasal",
"needled",
"newbie",
"nihilist",
"nobby",
"nomadic",
"nonexistent",
"nonplussed",
"nordic",
"nosy",
"nuanced",
"odd",
"oily",
"old",
"oldfashioned",
"olfactory",
"open",
"operatic",
"opining",
"opinionated",
"oppulent",
"orange",
"orbiting",
"ordered",
"orderly",
"original",
"ornery",
"peddling",
"peeking",
"pilfering",
"pining",
"pioneering",
"piquant",
"plinking",
"plucking",
"plundering",
"pondering",
"ponderous",
"pouring",
"precise",
"prodding",
"pruning",
"pugnacious",
"punk",
"quaffing",
"quarreling",
"quarrelsome",
"queenly",
"quelling",
"quiet",
"quieting",
"quoting",
"rafting",
"ranting",
"reeling",
"right",
"righteous",
"ringed",
"riotous",
"roiling",
"rolling",
"romping",
"rousing",
"rude",
"running",
"sad",
"sanguine",
"sappy",
"sartorial",
"saucy",
"silly",
"singed",
"singing",
"smelly",
"snug",
"soft",
"solemn",
"solid",
"solitary",
"steely",
"stultified",
"sullen",
"sweet",
"tailored",
"tan",
"telling",
"terrific",
"terrifying",
"tinseled",
"toned",
"torpid",
"torrid",
"trendsetting",
"trendy",
"triangular",
"truculent",
"tufted",
"turbulent",
"ugly",
"ulterior",
"undercooked",
"understood",
"ungaged",
"unhinged",
"unrealistic",
"unrealized",
"unsung",
"veering",
"vehement",
"vested",
"vetoed",
"viable",
"vigilant",
"virtuous",
"virulent",
"vocal",
"vociferous",
"volted",
"voting",
"wandering",
"wanton",
"warped",
"washed",
"washing",
"waxen",
"wayfaring",
"whimsical",
"wistful",
"whopping",
"wiggly",
"willing",
"winning",
"winsome",
"wintering",
"wise",
"wishful",
"wishing",
"wizened",
"wobbling",
"wobbly",
"womping",
"wonderful",
"wondering",
"worn",
"wrapping",
"wrinkled",
"xrayed",
"yellow",
"yodeling",
"youngling",
"your",
"youthful",
"yucky",
"yummy",
"zealous",
"zeroed",
"zinc",
"zooming",
}
+66
View File
@@ -0,0 +1,66 @@
package moniker
import (
"math/rand"
"strings"
"time"
)
// New returns a generic namer using the default word lists.
func New() Namer {
return &defaultNamer{
Descriptor: Descriptors,
Noun: Animals,
r: rand.New(rand.NewSource(time.Now().UnixNano())),
}
}
type defaultNamer struct {
Descriptor, Noun []string
r *rand.Rand
}
func (n *defaultNamer) NameSep(sep string) string {
a := n.Descriptor[n.r.Intn(len(n.Descriptor))]
b := n.Noun[n.r.Intn(len(n.Noun))]
return strings.Join([]string{a, b}, sep)
}
func (n *defaultNamer) Name() string {
return n.NameSep(" ")
}
// NewAlliterator returns a Namer that alliterates.
//
// wonky wombat
// racing rabbit
// alliterating alligator
//
// FIXME: This isn't working yet.
func NewAlliterator() Namer {
return &alliterator{
Descriptor: Descriptors,
Noun: Animals,
r: rand.New(rand.NewSource(time.Now().UnixNano())),
}
}
type alliterator struct {
Descriptor, Noun []string
r *rand.Rand
}
func (n *alliterator) Name() string {
return n.NameSep(" ")
}
func (n *alliterator) NameSep(sep string) string {
return ""
}
// Namer describes anything capable of generating a name.
type Namer interface {
// Name returns a generated name.
Name() string
// NameSep returns a generated name with words separated by the given string.
NameSep(string) string
}
+2
View File
@@ -0,0 +1,2 @@
//go:generate _generator/to_list descriptors.txt animals.txt
package moniker