gofmt
This commit is contained in:
parent
110361361b
commit
b4b0b737a3
4
main.go
4
main.go
|
@ -1,13 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.mowie.cc/konrad/Library/routes"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"git.mowie.cc/konrad/Library/routes"
|
||||
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main(){
|
||||
func main() {
|
||||
|
||||
// Set Engine
|
||||
err := models.SetEngine()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package models
|
||||
|
||||
func AddAuthor(author Author) (newAuthor Author, err error){
|
||||
func AddAuthor(author Author) (newAuthor Author, err error) {
|
||||
_, err = x.Insert(&author)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -9,7 +9,7 @@ func DeleteAuthorByID(id int64) error {
|
|||
}
|
||||
|
||||
// Delete all book relations associated with that author
|
||||
_, err = x.Delete(&AuthorBook{AuthorID:id})
|
||||
_, err = x.Delete(&AuthorBook{AuthorID: id})
|
||||
|
||||
return err
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package models
|
||||
|
||||
|
||||
func ListAuthors(searchterm string) (authors []Author, err error) {
|
||||
|
||||
if searchterm == "" {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package models
|
||||
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -17,7 +17,7 @@ type Book struct {
|
|||
Authors []Author `xorm:"-"`
|
||||
}
|
||||
|
||||
func (Book) TableName() string{
|
||||
func (Book) TableName() string {
|
||||
return "books"
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ die Datenbank eingetragen und mit dem Buch verknüpft.
|
|||
Bei den Autoren wirdebenfalls überprüft, ob sie bereits existieren, wenn dem nicht so ist werden
|
||||
sie in die Datenbank eingetragen und mit dem Buch verknüpft.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
func AddBook(book Book) (newBook Book, err error) {
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ func DeleteBookByID(id int64) error {
|
|||
}
|
||||
|
||||
// Delete all authors associated with that book
|
||||
_, err = x.Delete(&AuthorBook{BookID:id})
|
||||
_, err = x.Delete(&AuthorBook{BookID: id})
|
||||
|
||||
return err
|
||||
}
|
|
@ -17,13 +17,12 @@ func ListBooks(searchterm string) (books []*Book, err error) {
|
|||
fmt.Println("Error getting Books", err)
|
||||
}
|
||||
} else {
|
||||
err = x.Where("title LIKE ?", "%" + searchterm + "%").Find(&books)
|
||||
err = x.Where("title LIKE ?", "%"+searchterm+"%").Find(&books)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting Books", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get all authors and publishers
|
||||
for i, book := range books {
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
var Config struct{
|
||||
Database struct{
|
||||
var Config struct {
|
||||
Database struct {
|
||||
Host string
|
||||
User string
|
||||
Password string
|
||||
|
@ -16,7 +16,7 @@ var Config struct{
|
|||
JWTLoginSecret []byte
|
||||
}
|
||||
|
||||
func SetConfig() error{
|
||||
func SetConfig() error {
|
||||
|
||||
// File Checks
|
||||
if _, err := os.Stat("config.ini"); os.IsNotExist(err) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package models
|
||||
|
||||
type Message struct{
|
||||
type Message struct {
|
||||
Message string
|
||||
}
|
|
@ -1,21 +1,20 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"github.com/go-xorm/core"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-xorm/xorm"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
var x *xorm.Engine
|
||||
|
||||
func getEngine() (*xorm.Engine, error){
|
||||
func getEngine() (*xorm.Engine, error) {
|
||||
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true",
|
||||
"root", "jup2000", "127.0.0.1", "library2")
|
||||
return xorm.NewEngine("mysql", connStr)
|
||||
}
|
||||
|
||||
|
||||
// SetEngine sets the xorm.Engine
|
||||
func SetEngine() (err error) {
|
||||
x, err = getEngine()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package models
|
||||
|
||||
func AddPublisher(publisher Publisher) (newPublisher Publisher, err error){
|
||||
func AddPublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
||||
_, err = x.Insert(&publisher)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -12,8 +12,7 @@ func DeletePublisherByID(id int64) error {
|
|||
//book := Book{Publisher:0}
|
||||
//book.Publisher = 0
|
||||
//_, err = x.Where("publisher = ?", id).Update(book)
|
||||
_, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher":0})
|
||||
|
||||
_, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher": 0})
|
||||
|
||||
return err
|
||||
}
|
|
@ -6,7 +6,7 @@ func ListPublishers(searchterm string) (publishers []Publisher, err error) {
|
|||
err = x.Find(&publishers)
|
||||
} else {
|
||||
err = x.
|
||||
Where("name LIKE ?", "%" + searchterm + "%").
|
||||
Where("name LIKE ?", "%"+searchterm+"%").
|
||||
Find(&publishers)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package models
|
||||
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -26,10 +26,10 @@ func HashPassword(password string) (string, error) {
|
|||
}
|
||||
|
||||
// Check user credentials
|
||||
func CheckUserCredentials (username, password string) (User, error) {
|
||||
func CheckUserCredentials(username, password string) (User, error) {
|
||||
|
||||
// Check if the user exists
|
||||
var user = User{Username:username}
|
||||
var user = User{Username: username}
|
||||
exists, err := x.Get(&user)
|
||||
if err != nil {
|
||||
return User{}, err
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"strconv"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func AuthorDelete(c echo.Context) error {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
)
|
||||
|
||||
func AuthorsList(c echo.Context) error {
|
||||
|
||||
list, err := models.ListAuthors("")
|
||||
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ func AuthorSearch(c echo.Context) error {
|
|||
// Get the Authors
|
||||
list, err := models.ListAuthors(search)
|
||||
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
|
||||
}
|
||||
|
||||
// Check if we have any results
|
||||
if len(list) == 0{
|
||||
if len(list) == 0 {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any authors matching your search term"})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func AuthorUpdate(c echo.Context) error {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"strconv"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func BookDelete(c echo.Context) error {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ func BookList(c echo.Context) error {
|
|||
|
||||
list, err := models.ListBooks("")
|
||||
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ func BookSearch(c echo.Context) error {
|
|||
// Get the Books
|
||||
list, err := models.ListBooks(search)
|
||||
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
|
||||
}
|
||||
|
||||
// Check if we have any results
|
||||
if len(list) == 0{
|
||||
if len(list) == 0 {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any books matching your search term"})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"strconv"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func PublisherDelete(c echo.Context) error {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
)
|
||||
|
||||
func PublishersList(c echo.Context) error {
|
||||
|
||||
list, err := models.ListPublishers("")
|
||||
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers"})
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ func PublisherSearch(c echo.Context) error {
|
|||
// Get the Publishers
|
||||
list, err := models.ListPublishers(search)
|
||||
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher"})
|
||||
}
|
||||
|
||||
// Check if we have any results
|
||||
if len(list) == 0{
|
||||
if len(list) == 0 {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any publisher matching your search term"})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func PublisherUpdate(c echo.Context) error {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"fmt"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
func CheckToken(c echo.Context) error {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"time"
|
||||
"net/http"
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Login(c echo.Context) error {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
apiv1 "git.mowie.cc/konrad/Library/routes/api/v1"
|
||||
"github.com/labstack/echo"
|
||||
"github.com/labstack/echo/middleware"
|
||||
apiv1 "git.mowie.cc/konrad/Library/routes/api/v1"
|
||||
|
||||
"git.mowie.cc/konrad/Library/models"
|
||||
)
|
||||
|
@ -44,7 +44,6 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
// Login Route
|
||||
e.POST("/login", Login)
|
||||
|
||||
|
||||
// ===== Routes with Authetification =====
|
||||
// Authetification
|
||||
a.Use(middleware.JWT(models.Config.JWTLoginSecret))
|
||||
|
|
Loading…
Reference in New Issue