Fixed lint
the build failed Details

This commit is contained in:
konrad 2017-11-08 10:55:17 +01:00 committed by kolaente
parent bbfb661bab
commit 64dd0ce2d0
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
38 changed files with 55 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package models package models
// Author holds infos about an author
type Author struct { type Author struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Forename string `xorm:"varchar(250)"` Forename string `xorm:"varchar(250)"`
@ -8,10 +9,12 @@ type Author struct {
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
// TableName returns the table name for struct author
func (Author) TableName() string { func (Author) TableName() string {
return "authors" return "authors"
} }
// AuthorBook holds the relation between an author and a books
type AuthorBook struct { type AuthorBook struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
AuthorID int64 `xorm:"int(11)"` AuthorID int64 `xorm:"int(11)"`
@ -21,10 +24,12 @@ type AuthorBook struct {
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
// TableName returns the name for the relation author <-> book
func (AuthorBook) TableName() string { func (AuthorBook) TableName() string {
return "authors_books" return "authors_books"
} }
// GetAuthorByID gets information about an author by its ID
func GetAuthorByID(id int64) (author Author, exists bool, err error) { func GetAuthorByID(id int64) (author Author, exists bool, err error) {
has, err := x.Id(id).Get(&author) has, err := x.Id(id).Get(&author)

View File

@ -1,5 +1,6 @@
package models package models
// AddAuthor adds a new author based on an author struct
func AddAuthor(author Author) (newAuthor Author, err error) { func AddAuthor(author Author) (newAuthor Author, err error) {
_, err = x.Insert(&author) _, err = x.Insert(&author)

View File

@ -1,5 +1,6 @@
package models package models
// DeleteAuthorByID deletes an author by its ID
func DeleteAuthorByID(id int64) error { func DeleteAuthorByID(id int64) error {
// Delete the author // Delete the author
_, err := x.Id(id).Delete(&Author{}) _, err := x.Id(id).Delete(&Author{})

View File

@ -1,5 +1,6 @@
package models package models
// ListAuthors returns a list with all authors, filtered by an optional searchstring
func ListAuthors(searchterm string) (authors []Author, err error) { func ListAuthors(searchterm string) (authors []Author, err error) {
if searchterm == "" { if searchterm == "" {

View File

@ -1,5 +1,6 @@
package models package models
// UpdateAuthor updates an author by its ID and a new author struct
func UpdateAuthor(author Author, id int64) (newAuthor Author, err error) { func UpdateAuthor(author Author, id int64) (newAuthor Author, err error) {
_, err = x.Where("id = ?", id).Update(&author) _, err = x.Where("id = ?", id).Update(&author)

View File

@ -2,6 +2,7 @@ package models
import "fmt" import "fmt"
// Book holds a book
type Book struct { type Book struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Title string `xorm:"varchar(250) not null"` Title string `xorm:"varchar(250) not null"`
@ -17,11 +18,13 @@ type Book struct {
Authors []Author `xorm:"-"` Authors []Author `xorm:"-"`
} }
// TableName returns the name for the books table
func (Book) TableName() string { func (Book) TableName() string {
return "books" return "books"
} }
func GetBookById(ID int64) (book Book, exists bool, err error) { // GetBookByID gets a Book by its ID
func GetBookByID(ID int64) (book Book, exists bool, err error) {
// Get the Book // Get the Book
has, err := x.ID(ID).Get(&book) has, err := x.ID(ID).Get(&book)

View File

@ -15,6 +15,7 @@ sie in die Datenbank eingetragen und mit dem Buch verknüpft.
*/ */
// AddBook adds a new book, it takes a book struct with author and publisher. Inserts them if they don't already exist
func AddBook(book Book) (newBook Book, err error) { func AddBook(book Book) (newBook Book, err error) {
// Take Publisher, check if it exists. If not, insert it // Take Publisher, check if it exists. If not, insert it

View File

@ -1,5 +1,6 @@
package models package models
// DeleteBookByID deletes a book by its ID
func DeleteBookByID(id int64) error { func DeleteBookByID(id int64) error {
// Delete the book // Delete the book
_, err := x.Id(id).Delete(&Book{}) _, err := x.Id(id).Delete(&Book{})

View File

@ -2,11 +2,13 @@ package models
import "fmt" import "fmt"
// BookPublisher struct to join books with publishers
type BookPublisher struct { type BookPublisher struct {
Book `xorm:"extends"` Book `xorm:"extends"`
Publisher `xorm:"extends"` Publisher `xorm:"extends"`
} }
// ListBooks returns a list with all books, filtered by an optional searchstring
func ListBooks(searchterm string) (books []*Book, err error) { func ListBooks(searchterm string) (books []*Book, err error) {
if searchterm == "" { if searchterm == "" {

View File

@ -5,6 +5,7 @@ import (
"os" "os"
) )
// Config holds the config struct
var Config struct { var Config struct {
Database struct { Database struct {
Host string Host string
@ -16,6 +17,7 @@ var Config struct {
JWTLoginSecret []byte JWTLoginSecret []byte
} }
// SetConfig initianlises the config and publishes it for other functions to use
func SetConfig() error { func SetConfig() error {
// File Checks // File Checks

View File

@ -1,5 +1,6 @@
package models package models
// Message is a standard message
type Message struct { type Message struct {
Message string Message string
} }

View File

@ -2,7 +2,7 @@ package models
import ( import (
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql" // Because.
"github.com/go-xorm/core" "github.com/go-xorm/core"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
) )

View File

@ -1,5 +1,6 @@
package models package models
// Publisher holds publisher informations
type Publisher struct { type Publisher struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Name string `xorm:"varchar(250) not null"` Name string `xorm:"varchar(250) not null"`
@ -7,10 +8,12 @@ type Publisher struct {
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
// TableName returns the table name for publishers struct
func (Publisher) TableName() string { func (Publisher) TableName() string {
return "publishers" return "publishers"
} }
// GetPublisherByID returns a publisher by its ID
func GetPublisherByID(id int64) (publisher Publisher, exists bool, err error) { func GetPublisherByID(id int64) (publisher Publisher, exists bool, err error) {
has, err := x.Id(id).Get(&publisher) has, err := x.Id(id).Get(&publisher)

View File

@ -1,5 +1,6 @@
package models package models
// AddPublisher adds a publisher from a publisher struct
func AddPublisher(publisher Publisher) (newPublisher Publisher, err error) { func AddPublisher(publisher Publisher) (newPublisher Publisher, err error) {
_, err = x.Insert(&publisher) _, err = x.Insert(&publisher)

View File

@ -1,5 +1,6 @@
package models package models
// DeletePublisherByID deletes a publisher by its ID
func DeletePublisherByID(id int64) error { func DeletePublisherByID(id int64) error {
// Delete the publisher // Delete the publisher
_, err := x.Id(id).Delete(&Publisher{}) _, err := x.Id(id).Delete(&Publisher{})

View File

@ -1,5 +1,6 @@
package models package models
// ListPublishers returns a list with all publishers, filtered by an optional searchstring
func ListPublishers(searchterm string) (publishers []Publisher, err error) { func ListPublishers(searchterm string) (publishers []Publisher, err error) {
if searchterm == "" { if searchterm == "" {

View File

@ -1,5 +1,6 @@
package models package models
// UpdatePublisher updates a publisher, takes an ID and a publisher struct with the new publisher infos
func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error) { func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error) {
_, err = x.Where("id = ?", id).Update(&publisher) _, err = x.Where("id = ?", id).Update(&publisher)

View File

@ -5,6 +5,7 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
// User holds information about an user
type User struct { type User struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Name string `xorm:"varchar(250)"` Name string `xorm:"varchar(250)"`
@ -15,17 +16,18 @@ type User struct {
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
// TableName returns the table name for users
func (User) TableName() string { func (User) TableName() string {
return "users" return "users"
} }
// Hash a password // HashPassword hashes a password
func HashPassword(password string) (string, error) { func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err return string(bytes), err
} }
// Check user credentials // CheckUserCredentials checks user credentials
func CheckUserCredentials(username, password string) (User, error) { func CheckUserCredentials(username, password string) (User, error) {
// Check if the user exists // Check if the user exists
@ -36,7 +38,7 @@ func CheckUserCredentials(username, password string) (User, error) {
} }
if !exists { if !exists {
return User{}, fmt.Errorf("User does not exist!") return User{}, fmt.Errorf("user does not exist")
} }
// Check the users password // Check the users password

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
) )
// AuthorDelete is the handler for deleting an author
func AuthorDelete(c echo.Context) error { func AuthorDelete(c echo.Context) error {
id := c.Param("id") id := c.Param("id")

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
) )
// AuthorShow is the handler to show an author
func AuthorShow(c echo.Context) error { func AuthorShow(c echo.Context) error {
author := c.Param("id") author := c.Param("id")

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
) )
// AuthorAdd is the handler to add an author
func AuthorAdd(c echo.Context) error { func AuthorAdd(c echo.Context) error {
// Check for Request Content // Check for Request Content
author := c.FormValue("author") author := c.FormValue("author")

View File

@ -6,6 +6,7 @@ import (
"net/http" "net/http"
) )
// AuthorsList is the handler to list authors
func AuthorsList(c echo.Context) error { func AuthorsList(c echo.Context) error {
list, err := models.ListAuthors("") list, err := models.ListAuthors("")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
) )
// AuthorSearch is the handler to search for authors
func AuthorSearch(c echo.Context) error { func AuthorSearch(c echo.Context) error {
// Prepare the searchterm // Prepare the searchterm

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
) )
// AuthorUpdate is the handler to update an author
func AuthorUpdate(c echo.Context) error { func AuthorUpdate(c echo.Context) error {
// Check for Request Content // Check for Request Content
author := c.FormValue("author") author := c.FormValue("author")

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
) )
// BookDelete is the handler to delete a book
func BookDelete(c echo.Context) error { func BookDelete(c echo.Context) error {
id := c.Param("id") id := c.Param("id")

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
) )
// BookShow is the handler to show informations about a book
func BookShow(c echo.Context) error { func BookShow(c echo.Context) error {
book := c.Param("id") book := c.Param("id")

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
) )
// BookAdd is the handler to add a book
func BookAdd(c echo.Context) error { func BookAdd(c echo.Context) error {
// Check for Request Content // Check for Request Content
book := c.FormValue("book") book := c.FormValue("book")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
) )
// BookList is the handler to list books
func BookList(c echo.Context) error { func BookList(c echo.Context) error {
list, err := models.ListBooks("") list, err := models.ListBooks("")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
) )
// BookSearch is the handler to search for books
func BookSearch(c echo.Context) error { func BookSearch(c echo.Context) error {
// Prepare the searchterm // Prepare the searchterm

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
) )
// PublisherShow is the handler to show informations about a publisher
func PublisherShow(c echo.Context) error { func PublisherShow(c echo.Context) error {
publisher := c.Param("id") publisher := c.Param("id")

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
) )
// PublisherAdd is the handler to add a publisher
func PublisherAdd(c echo.Context) error { func PublisherAdd(c echo.Context) error {
// Check for Request Content // Check for Request Content
publisher := c.FormValue("publisher") publisher := c.FormValue("publisher")

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
) )
// PublisherDelete is the handler to delete a publisher
func PublisherDelete(c echo.Context) error { func PublisherDelete(c echo.Context) error {
id := c.Param("id") id := c.Param("id")

View File

@ -6,6 +6,7 @@ import (
"net/http" "net/http"
) )
// PublishersList is the handler to list publishers
func PublishersList(c echo.Context) error { func PublishersList(c echo.Context) error {
list, err := models.ListPublishers("") list, err := models.ListPublishers("")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
) )
// PublisherSearch is the handler to search for a publisher
func PublisherSearch(c echo.Context) error { func PublisherSearch(c echo.Context) error {
// Prepare the searchterm // Prepare the searchterm

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
) )
// PublisherUpdate is the handler to update a publishers information
func PublisherUpdate(c echo.Context) error { func PublisherUpdate(c echo.Context) error {
// Check for Request Content // Check for Request Content
publisher := c.FormValue("publisher") publisher := c.FormValue("publisher")

View File

@ -6,6 +6,7 @@ import (
"github.com/labstack/echo" "github.com/labstack/echo"
) )
// CheckToken checks prints a message if the token is valid or not. Currently only used for testing pourposes.
func CheckToken(c echo.Context) error { func CheckToken(c echo.Context) error {
user := c.Get("user").(*jwt.Token) user := c.Get("user").(*jwt.Token)

View File

@ -8,6 +8,7 @@ import (
"time" "time"
) )
// Login is the login handler
func Login(c echo.Context) error { func Login(c echo.Context) error {
username := c.FormValue("username") username := c.FormValue("username")
password := c.FormValue("password") password := c.FormValue("password")

View File

@ -8,6 +8,7 @@ import (
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
) )
// NewEcho registers a new Echo instance
func NewEcho() *echo.Echo { func NewEcho() *echo.Echo {
e := echo.New() e := echo.New()
@ -22,6 +23,7 @@ func NewEcho() *echo.Echo {
return e return e
} }
// RegisterRoutes registers all routes for the application
func RegisterRoutes(e *echo.Echo) { func RegisterRoutes(e *echo.Echo) {
// API Routes // API Routes