feat: linting
This commit is contained in:
@ -48,10 +48,8 @@ func (h *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
w.Header().Set("Content-Type", http.DetectContentType(file.Data))
|
||||
w.Write(file.Data)
|
||||
return
|
||||
} else {
|
||||
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,12 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ItemHandler struct {
|
||||
type Handler struct {
|
||||
db *gorm.DB
|
||||
key []byte
|
||||
}
|
||||
|
||||
func (h *ItemHandler) GetItem(ctx context.Context, req *connect.Request[itemv1.GetItemRequest]) (*connect.Response[itemv1.GetItemResponse], error) {
|
||||
func (h *Handler) GetItem(ctx context.Context, req *connect.Request[itemv1.GetItemRequest]) (*connect.Response[itemv1.GetItemResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -38,7 +38,7 @@ func (h *ItemHandler) GetItem(ctx context.Context, req *connect.Request[itemv1.G
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *ItemHandler) GetItems(ctx context.Context, req *connect.Request[itemv1.GetItemsRequest]) (*connect.Response[itemv1.GetItemsResponse], error) {
|
||||
func (h *Handler) GetItems(ctx context.Context, req *connect.Request[itemv1.GetItemsRequest]) (*connect.Response[itemv1.GetItemsResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -88,7 +88,7 @@ func (h *ItemHandler) GetItems(ctx context.Context, req *connect.Request[itemv1.
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *ItemHandler) CreateItem(ctx context.Context, req *connect.Request[itemv1.CreateItemRequest]) (*connect.Response[itemv1.CreateItemResponse], error) {
|
||||
func (h *Handler) CreateItem(ctx context.Context, req *connect.Request[itemv1.CreateItemRequest]) (*connect.Response[itemv1.CreateItemResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -113,7 +113,7 @@ func (h *ItemHandler) CreateItem(ctx context.Context, req *connect.Request[itemv
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *ItemHandler) UpdateItem(ctx context.Context, req *connect.Request[itemv1.UpdateItemRequest]) (*connect.Response[itemv1.UpdateItemResponse], error) {
|
||||
func (h *Handler) UpdateItem(ctx context.Context, req *connect.Request[itemv1.UpdateItemRequest]) (*connect.Response[itemv1.UpdateItemResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -143,7 +143,7 @@ func (h *ItemHandler) UpdateItem(ctx context.Context, req *connect.Request[itemv
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *ItemHandler) DeleteItem(ctx context.Context, req *connect.Request[itemv1.DeleteItemRequest]) (*connect.Response[itemv1.DeleteItemResponse], error) {
|
||||
func (h *Handler) DeleteItem(ctx context.Context, req *connect.Request[itemv1.DeleteItemRequest]) (*connect.Response[itemv1.DeleteItemResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -158,11 +158,11 @@ func (h *ItemHandler) DeleteItem(ctx context.Context, req *connect.Request[itemv
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func NewItemHandler(db *gorm.DB, key string) (string, http.Handler) {
|
||||
func NewHandler(db *gorm.DB, key string) (string, http.Handler) {
|
||||
interceptors := connect.WithInterceptors(interceptors.NewAuthInterceptor(key))
|
||||
|
||||
return itemv1connect.NewItemServiceHandler(
|
||||
&ItemHandler{
|
||||
&Handler{
|
||||
db: db,
|
||||
key: []byte(key),
|
||||
},
|
||||
|
@ -22,7 +22,7 @@ type AuthHandler struct {
|
||||
key []byte
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Login(ctx context.Context, req *connect.Request[userv1.LoginRequest]) (*connect.Response[userv1.LoginResponse], error) {
|
||||
func (h *AuthHandler) Login(_ context.Context, req *connect.Request[userv1.LoginRequest]) (*connect.Response[userv1.LoginResponse], error) {
|
||||
// Validate
|
||||
user := models.User{}
|
||||
if err := h.db.First(&user, "username = ?", req.Msg.Username).Error; err != nil {
|
||||
@ -69,7 +69,7 @@ func (h *AuthHandler) Login(ctx context.Context, req *connect.Request[userv1.Log
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *AuthHandler) SignUp(ctx context.Context, req *connect.Request[userv1.SignUpRequest]) (*connect.Response[userv1.SignUpResponse], error) {
|
||||
func (h *AuthHandler) SignUp(_ context.Context, req *connect.Request[userv1.SignUpRequest]) (*connect.Response[userv1.SignUpResponse], error) {
|
||||
// Validate
|
||||
if err := h.db.First(&models.User{}, "username = ?", req.Msg.Username).Error; err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@ -101,7 +101,7 @@ func (h *AuthHandler) SignUp(ctx context.Context, req *connect.Request[userv1.Si
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Logout(ctx context.Context, req *connect.Request[userv1.LogoutRequest]) (*connect.Response[userv1.LogoutResponse], error) {
|
||||
func (h *AuthHandler) Logout(_ context.Context, _ *connect.Request[userv1.LogoutRequest]) (*connect.Response[userv1.LogoutResponse], error) {
|
||||
// Clear cookie
|
||||
cookie := http.Cookie{
|
||||
Name: "token",
|
||||
|
@ -17,12 +17,12 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserHandler struct {
|
||||
type Handler struct {
|
||||
db *gorm.DB
|
||||
key []byte
|
||||
}
|
||||
|
||||
func (h *UserHandler) GetUser(ctx context.Context, req *connect.Request[userv1.GetUserRequest]) (*connect.Response[userv1.GetUserResponse], error) {
|
||||
func (h *Handler) GetUser(ctx context.Context, _ *connect.Request[userv1.GetUserRequest]) (*connect.Response[userv1.GetUserResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -40,7 +40,7 @@ func (h *UserHandler) GetUser(ctx context.Context, req *connect.Request[userv1.G
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *UserHandler) UpdatePassword(ctx context.Context, req *connect.Request[userv1.UpdatePasswordRequest]) (*connect.Response[userv1.UpdatePasswordResponse], error) {
|
||||
func (h *Handler) UpdatePassword(ctx context.Context, req *connect.Request[userv1.UpdatePasswordRequest]) (*connect.Response[userv1.UpdatePasswordResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -75,7 +75,7 @@ func (h *UserHandler) UpdatePassword(ctx context.Context, req *connect.Request[u
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *UserHandler) GetAPIKey(ctx context.Context, req *connect.Request[userv1.GetAPIKeyRequest]) (*connect.Response[userv1.GetAPIKeyResponse], error) {
|
||||
func (h *Handler) GetAPIKey(ctx context.Context, req *connect.Request[userv1.GetAPIKeyRequest]) (*connect.Response[userv1.GetAPIKeyResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -114,7 +114,7 @@ func (h *UserHandler) GetAPIKey(ctx context.Context, req *connect.Request[userv1
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (h *UserHandler) UpdateProfilePicture(ctx context.Context, req *connect.Request[userv1.UpdateProfilePictureRequest]) (*connect.Response[userv1.UpdateProfilePictureResponse], error) {
|
||||
func (h *Handler) UpdateProfilePicture(ctx context.Context, req *connect.Request[userv1.UpdateProfilePictureRequest]) (*connect.Response[userv1.UpdateProfilePictureResponse], error) {
|
||||
userid, ok := interceptors.GetUserContext(ctx)
|
||||
if !ok {
|
||||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unauthenticated"))
|
||||
@ -169,11 +169,11 @@ func (h *UserHandler) UpdateProfilePicture(ctx context.Context, req *connect.Req
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func NewUserHandler(db *gorm.DB, key string) (string, http.Handler) {
|
||||
func NewHandler(db *gorm.DB, key string) (string, http.Handler) {
|
||||
interceptors := connect.WithInterceptors(interceptors.NewAuthInterceptor(key))
|
||||
|
||||
return userv1connect.NewUserServiceHandler(
|
||||
&UserHandler{
|
||||
&Handler{
|
||||
db: db,
|
||||
key: []byte(key),
|
||||
},
|
||||
|
Reference in New Issue
Block a user