Nightly Push (Nothing Works)
This commit is contained in:
65
pkg/main-songs.go
Normal file
65
pkg/main-songs.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// package main
|
||||
|
||||
// import (
|
||||
// "errors"
|
||||
// "net/http"
|
||||
|
||||
// "github.com/gin-gonic/gin"
|
||||
// )
|
||||
|
||||
// type media struct {
|
||||
// ID string `json: "id"`
|
||||
// Url string `json: "url"`
|
||||
// Title string `json: "title"`
|
||||
// Author string `json: "author"`
|
||||
// }
|
||||
|
||||
// var songs = []media{
|
||||
// {ID: "1", Url: "https://www.youtube.com/watch?v=DmeUuoxyt_E", Title: "Rockstars", Author: "Nickelback"},
|
||||
// {ID: "2", Url: "https://www.youtube.com/watch?v=u9Dg-g7t2l4", Title: "The Sound Of Silence", Author: "Disturbed"},
|
||||
// {ID: "3", Url: "https://www.youtube.com/watch?v=uxUATkpMQ8A", Title: "Gives You Hell", Author: "The All-American Rejects"},
|
||||
// }
|
||||
|
||||
// func getMedia(c *gin.Context) {
|
||||
// c.IndentedJSON(http.StatusOK, songs)
|
||||
// }
|
||||
|
||||
// func songByid(c *gin.Context) {
|
||||
// id := c.Param("id")
|
||||
// song, err := getMediaByid(id)
|
||||
|
||||
// if err != nil {
|
||||
// c.IndentedJSON(http.StatusNotFound, gin.H{"message": "Book not found."})
|
||||
// return
|
||||
// }
|
||||
|
||||
// c.IndentedJSON(http.StatusOK, song)
|
||||
// }
|
||||
|
||||
// func getMediaByid(id string) (*media, error) {
|
||||
// for i, song := range songs {
|
||||
// if song.ID == id {
|
||||
// return &songs[i], nil
|
||||
// }
|
||||
// }
|
||||
// return nil, errors.New("id not found")
|
||||
// }
|
||||
|
||||
// func addMedia(c *gin.Context) {
|
||||
// var newSong media
|
||||
|
||||
// if err := c.BindJSON(&newSong); err != nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
// songs = append(songs, newSong)
|
||||
// c.IndentedJSON(http.StatusCreated, newSong)
|
||||
// }
|
||||
|
||||
// func main() {
|
||||
// router := gin.Default()
|
||||
// router.GET("/songs", getMedia)
|
||||
// router.GET("/songs/:id", songByid)
|
||||
// router.POST("/songs", addMedia)
|
||||
// router.Run("127.0.0.1:8000")
|
||||
// }
|
||||
49
pkg/main.go
Normal file
49
pkg/main.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func dbinit(db *sql.DB) {
|
||||
dbinit, err := db.Query("CREATE TABLE IF NOT EXISTS `media` (`id` INT NOT NULL AUTO_INCREMENT, `yt-id` VARCHAR(100), `url` VARCHAR(255), `localpath` TEXT(65535), `size` INT, `sha256sum` VARCHAR(255), `length` INT, PRIMARY KEY (`id`));")
|
||||
if err != nil {
|
||||
fmt.Println("Error while creating table")
|
||||
panic(err.Error())
|
||||
}
|
||||
defer dbinit.Close()
|
||||
fmt.Println("DB-Init successfull")
|
||||
}
|
||||
|
||||
func dbentrycount(db *sql.DB) {
|
||||
var count int
|
||||
dbcount, err := db.Query("SELECT COUNT(*) FROM testdb.media;")
|
||||
if err != nil {
|
||||
fmt.Println("Error while counting rows from table")
|
||||
panic(err.Error())
|
||||
}
|
||||
defer dbcount.Close()
|
||||
for dbcount.Next() {
|
||||
err = dbcount.Scan(&count)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
fmt.Printf("There are %v entries in the database\n", count)
|
||||
}
|
||||
|
||||
func main() {
|
||||
db, err := sql.Open("mysql", "username:password@tcp(127.0.0.1:3306)/testdb")
|
||||
if err != nil {
|
||||
fmt.Println("Error while connecting with the database")
|
||||
panic(err.Error())
|
||||
}
|
||||
fmt.Println("Successfully connected to the database")
|
||||
defer db.Close()
|
||||
|
||||
dbinit(db)
|
||||
|
||||
dbentrycount(db)
|
||||
}
|
||||
Reference in New Issue
Block a user