Skip to content

Commit

Permalink
Merge pull request #3 from tsunagatteru/dev
Browse files Browse the repository at this point in the history
Removed interface conversion from vipe calls
  • Loading branch information
tsunagatteru authored May 6, 2023
2 parents adf8878 + 242c32d commit 509fc0f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/inn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

func main() {
variables := options.GetVar()
resPath := variables.Get("res-path").(string)
dataPath := variables.Get("data-path").(string)
resPath := variables.GetString("res-path")
dataPath := variables.GetString("data-path")
var resources fs.FS
if resPath == "embed" {
resources = res.GetEmbedFS()
Expand Down
2 changes: 1 addition & 1 deletion server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func login(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Parameters can't be empty"})
return
}
if username != config.Get("username").(string) || password != config.Get("password").(string) {
if username != config.Get("username").(string) || password != config.GetString("password") {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Authentication failed"})
return
}
Expand Down
9 changes: 4 additions & 5 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func showIndex(c *gin.Context) {
dbConn := c.MustGet("dbConn").(*sql.DB)
variables := c.MustGet("variables").(*viper.Viper)
pageLength := variables.Get("page-length").(int)
pageLength := variables.GetInt("page-length")
posts := db.RetrievePage(dbConn, 1, pageLength)
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Posts": posts,
Expand All @@ -33,9 +33,8 @@ func showPosts(c *gin.Context) {
}
dbConn := c.MustGet("dbConn").(*sql.DB)
variables := c.MustGet("variables").(*viper.Viper)
pageLength := variables.Get("page-length").(int)
pageLength := variables.GetInt("page-length")
posts := db.RetrievePage(dbConn, pageNumber, pageLength)

c.HTML(http.StatusOK, "posts.tmpl", gin.H{
"Posts": posts,
})
Expand Down Expand Up @@ -65,7 +64,7 @@ func getPosts(c *gin.Context) {
}
dbConn := c.MustGet("dbConn").(*sql.DB)
variables := c.MustGet("variables").(*viper.Viper)
pageLength := variables.Get("page-length").(int)
pageLength := variables.GetInt("page-length")
posts := db.RetrievePage(dbConn, pageNumber, pageLength)
c.JSON(http.StatusOK, posts)
}
Expand All @@ -91,7 +90,7 @@ func createPost(c *gin.Context) {
if err != nil {
log.Println(err)
}
dataPath := variables.Get("data-path").(string)
dataPath := variables.GetString("data-path")
files := form.File["files"]
var filename string
if len(files) != 0 {
Expand Down
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func Run(resources fs.FS, variables *viper.Viper, config *viper.Viper) {
dbConn := db.Open(variables.Get("data-path").(string))
dbConn := db.Open(variables.GetString("data-path"))
defer dbConn.Close()
db.CreateTable(dbConn)
r := gin.New()
Expand All @@ -27,13 +27,13 @@ func Run(resources fs.FS, variables *viper.Viper, config *viper.Viper) {
log.Fatalln(err)
}
r.StaticFS("/static", http.FS(staticRoot))
imagesRoot, err := fs.Sub(os.DirFS(variables.Get("data-path").(string)), "images")
imagesRoot, err := fs.Sub(os.DirFS(variables.GetString("data-path")), "images")
if err != nil {
log.Fatalln(err)
}
r.StaticFS("/images", http.FS(imagesRoot))
r.Use(Middleware(dbConn, variables, config))
r.Use(sessions.Sessions("mysession", cookie.NewStore([]byte((config.Get("cookiekey").(string))))))
r.Use(sessions.Sessions("mysession", cookie.NewStore([]byte((config.GetString("cookiekey"))))))
api := r.Group("/api")
api.GET("/posts/:page", getPosts)
api.GET("post/:id", getPost)
Expand Down

0 comments on commit 509fc0f

Please sign in to comment.