Minimal linting improvements

This commit is contained in:
Jan Bader 2022-02-20 21:19:28 +00:00
parent 545f223a97
commit c03d16878a
10 changed files with 23 additions and 17 deletions

View File

@ -51,7 +51,7 @@ var (
)
// VerifyToken verifys a given string-token.
func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) {
func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) { //nolint:ireturn
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("method '%v': %w", token.Header["alg"], ErrUnexpectedSigningMethod)

View File

@ -8,7 +8,7 @@ import (
"github.com/google/uuid"
)
// NewBudget creates a budget and adds it to the current user
// NewBudget creates a budget and adds it to the current user.
func (s *Database) NewBudget(context context.Context, name string, userID uuid.UUID) (*Budget, error) {
tx, err := s.BeginTx(context, &sql.TxOptions{})
if err != nil {

View File

@ -17,7 +17,7 @@ type Database struct {
*sql.DB
}
// Connect to a database
// Connect connects to a database.
func Connect(typ string, connString string) (*Database, error) {
conn, err := sql.Open(typ, connString)
if err != nil {

View File

@ -56,7 +56,7 @@ func NewYNABImport(context context.Context, queries *Queries, budgetID uuid.UUID
// "Month" "Category Group/Category" "Category Group" "Category" "Budgeted" "Activity" "Available"
// "Apr 2019" "Income: Next Month" "Income" "Next Month" 0,00€ 0,00€ 0,00€
//
// Activity and Available are not imported, since they are determined by the transactions and historic assignments
// Activity and Available are not imported, since they are determined by the transactions and historic assignments.
func (ynab *YNABImport) ImportAssignments(context context.Context, r io.Reader) error {
csv := csv.NewReader(r)
csv.Comma = '\t'
@ -184,7 +184,8 @@ func (ynab *YNABImport) ImportTransactions(context context.Context, r io.Reader)
// Transaction is a transfer to
var shouldReturn bool
var returnValue error
openTransfers, shouldReturn, returnValue = ynab.ImportTransaction(payeeName, context, transaction, accountName, openTransfers, account, amount)
openTransfers, shouldReturn, returnValue = ynab.ImportTransaction(
payeeName, context, transaction, accountName, openTransfers, account, amount)
if shouldReturn {
return returnValue
}
@ -368,13 +369,15 @@ func (ynab *YNABImport) GetCategory(context context.Context, group string, name
}
}
categoryGroup, err := ynab.queries.CreateCategoryGroup(context, CreateCategoryGroupParams{Name: group, BudgetID: ynab.budgetID})
newGroup := CreateCategoryGroupParams{Name: group, BudgetID: ynab.budgetID}
categoryGroup, err := ynab.queries.CreateCategoryGroup(context, newGroup)
if err != nil {
return uuid.NullUUID{}, err
}
ynab.categoryGroups = append(ynab.categoryGroups, categoryGroup)
category, err := ynab.queries.CreateCategory(context, CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID})
newCategory := CreateCategoryParams{Name: name, CategoryGroupID: categoryGroup.ID}
category, err := ynab.queries.CreateCategory(context, newCategory)
if err != nil {
return uuid.NullUUID{}, err
}

View File

@ -14,7 +14,7 @@ import (
"github.com/gin-gonic/gin"
)
func init() {
func init() { //nolint:gochecknoinits
txdb.Register("pgtx", "pgx", "postgres://budgeteer_test:budgeteer_test@localhost:5432/budgeteer_test")
}

View File

@ -1,7 +1,6 @@
package server
import (
"fmt"
"net/http"
"git.javil.eu/jacob1123/budgeteer/postgres"
@ -13,7 +12,7 @@ func (h *Handler) autocompleteCategories(c *gin.Context) {
budgetID := c.Param("budgetid")
budgetUUID, err := uuid.Parse(budgetID)
if err != nil {
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL"))
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"})
return
}
@ -35,7 +34,7 @@ func (h *Handler) autocompletePayee(c *gin.Context) {
budgetID := c.Param("budgetid")
budgetUUID, err := uuid.Parse(budgetID)
if err != nil {
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL"))
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"})
return
}

View File

@ -1,7 +1,6 @@
package server
import (
"fmt"
"net/http"
"git.javil.eu/jacob1123/budgeteer"
@ -20,7 +19,7 @@ func (h *Handler) newBudget(c *gin.Context) {
}
if newBudget.Name == "" {
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("Budget name is needed"))
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budget name is required"})
return
}

View File

@ -85,7 +85,8 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
}
// skip everything in the future
categoriesWithBalance, moneyUsed, err := h.calculateBalances(c, budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances)
categoriesWithBalance, moneyUsed, err := h.calculateBalances(
c, budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances)
if err != nil {
return
}

View File

@ -104,7 +104,11 @@ func (h *Handler) ServeStaticFile(c *gin.Context, fullPath string) {
return
}
http.ServeContent(c.Writer, c.Request, stat.Name(), stat.ModTime(), file.(io.ReadSeeker))
if file, ok := file.(io.ReadSeeker); ok {
http.ServeContent(c.Writer, c.Request, stat.Name(), stat.ModTime(), file)
} else {
panic("File does not implement ReadSeeker")
}
}
func enableCachingForStaticFiles() gin.HandlerFunc {

View File

@ -50,7 +50,7 @@ func (h *Handler) newTransaction(c *gin.Context) {
}*/
// if !transactionUUID.Valid {
new := postgres.CreateTransactionParams{
newTransaction := postgres.CreateTransactionParams{
Memo: payload.Memo,
Date: time.Time(payload.Date),
Amount: amount,
@ -59,7 +59,7 @@ func (h *Handler) newTransaction(c *gin.Context) {
CategoryID: payload.Category.ID, // TODO handle new category
Status: postgres.TransactionStatus(payload.State),
}
_, err = h.Service.CreateTransaction(c.Request.Context(), new)
_, err = h.Service.CreateTransaction(c.Request.Context(), newTransaction)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
}