45 lines
885 B
Go
45 lines
885 B
Go
package main
|
|
|
|
import (
|
|
"github.com/swaggo/http-swagger"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
"os"
|
|
_ "pokedex/docs"
|
|
"pokedex/pokemon"
|
|
)
|
|
|
|
func openNewDb() *gorm.DB {
|
|
os.Remove("pokedex.db")
|
|
db, err := gorm.Open(sqlite.Open("pokedex.db"), &gorm.Config{})
|
|
if err != nil {
|
|
panic("failed to connect database")
|
|
}
|
|
return db
|
|
}
|
|
|
|
// @title Pokedex
|
|
// @version 1.0
|
|
// @description A Pokedex Go Kata
|
|
|
|
// @contact.name Brain Baking
|
|
// @contact.url https://brainbaking.com
|
|
|
|
// @license.name MIT
|
|
// @license.url https://opensource.org/licenses/MIT
|
|
|
|
// @host localhost:8080
|
|
// @BasePath /
|
|
// @query.collection.format multi
|
|
func main() {
|
|
db := openNewDb()
|
|
pokemon.Seed(db)
|
|
|
|
routes(db)
|
|
http.HandleFunc("GET /docs/", httpSwagger.Handler(
|
|
httpSwagger.URL("http://localhost:8080/docs/doc.json"), //The url pointing to API definition
|
|
))
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|