Nightly Push (Nothing Works)

This commit is contained in:
janic
2022-04-11 23:49:18 +02:00
parent 8e3f729898
commit dd211c58c9
8 changed files with 265 additions and 0 deletions

65
pkg/main-songs.go Normal file
View 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
View 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)
}