Exemple #1
0
func main() {
	config, err := loadDatabases("config.json")
	if err != nil {
		log.Fatal(err)
	}

	server := dictd.NewServer(config.Name)

	for _, dbConfig := range config.Databases {
		db, err := database.NewLevelDBDatabase(
			dbConfig.Path,
			dbConfig.Desc,
		)
		if err != nil {
			log.Fatal(err)
		}
		server.RegisterDatabase(db, dbConfig.Name, true)
	}

	server.RegisterDatabase(&database.UrbanDictionaryDatabase{}, "urban", false)

	link, err := net.Listen("tcp", ":2628")
	if err != nil {
		log.Fatal(err)
	}

	for {
		conn, err := link.Accept()
		if err != nil {
			log.Printf("Error: %s", err)
		}
		go dictd.Handle(&server, conn)
	}
}
Exemple #2
0
func main() {
	if len(os.Args) < 3 {
		log.Fatal("Give me a path to the db and a path to a file")
	}

	path := os.Args[1]
	dbFile := os.Args[2]

	defs := format.ParseJargonFormat(dbFile)
	db, err := database.NewLevelDBDatabase(path, "")

	if err != nil {
		log.Fatal(err)
	}

	for _, def := range defs {
		word := strings.ToLower(def.Word)
		db.WriteDefinition(word, def.Definition)
	}

}