Fixed linter errors

This commit is contained in:
Eduard Urbach 2019-10-21 14:02:09 +09:00
parent 1819367160
commit 506fd3c0a7
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 45 additions and 43 deletions

View File

@ -11,6 +11,9 @@ linters:
- gochecknoglobals
- gochecknoinits
- gocyclo
- gocognit
- gosec
- maligned
- stylecheck
- funlen
- wsl

View File

@ -22,6 +22,7 @@ const (
var (
discordNickRegex = regexp.MustCompile(`^([^#]{2,32})#(\d{4})$`)
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
)
// Nick tests if the given nickname is valid.
@ -70,8 +71,7 @@ func YearMonth(date string) bool {
// Email tests if the given email address is valid.
func Email(email string) bool {
// TODO: Add email check
return email != ""
return emailRegex.MatchString(email)
}
// URI validates a URI.

View File

@ -28,6 +28,9 @@ func TestIsValidNick(t *testing.T) {
func TestIsValidEmail(t *testing.T) {
assert.False(t, validate.Email(""))
assert.False(t, validate.Email("ç$€§/az@gmail.com"))
assert.False(t, validate.Email("abc@gmail_yahoo.com"))
assert.True(t, validate.Email("abc@gmail-yahoo.com"))
assert.True(t, validate.Email("support@notify.moe"))
}

View File

@ -164,8 +164,6 @@ func InstallTwitterAuth(app *aero.Application) {
user.Nick = "tw" + twUser.ID
user.Email = twUser.Email
user.LastLogin = arn.DateTimeUTC()
// TODO: The full name is in the Name field
user.FirstName = twUser.Name
// Save basic user info already to avoid data inconsistency problems

View File

@ -1,9 +1,7 @@
package graphql
import (
"errors"
"fmt"
"reflect"
"strings"
"github.com/aerogo/aero"
@ -39,55 +37,55 @@ func Install(app *aero.Application) {
})
// Like objects
api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
if !strings.HasPrefix(name, "like") {
return nil, nil, false
}
// api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
// if !strings.HasPrefix(name, "like") {
// return nil, nil, false
// }
id, ok := arguments["ID"].(string)
// id, ok := arguments["ID"].(string)
if !ok {
return nil, fmt.Errorf("'%s' needs to specify an ID", name), true
}
// if !ok {
// return nil, fmt.Errorf("'%s' needs to specify an ID", name), true
// }
typeName := strings.TrimPrefix(name, "like")
obj, err := arn.DB.Get(typeName, id)
// typeName := strings.TrimPrefix(name, "like")
// obj, err := arn.DB.Get(typeName, id)
if err != nil {
return nil, err, true
}
// if err != nil {
// return nil, err, true
// }
field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft")
// field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft")
if field.IsValid() && field.Bool() {
return nil, errors.New("Drafts need to be published before they can be liked"), true
}
// if field.IsValid() && field.Bool() {
// return nil, errors.New("Drafts need to be published before they can be liked"), true
// }
likeable, ok := obj.(arn.Likeable)
// likeable, ok := obj.(arn.Likeable)
if !ok {
return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true
}
// if !ok {
// return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true
// }
// TODO: Authentication
// user := GetUserFromContext(ctx)
// // TODO: Authentication
// // user := GetUserFromContext(ctx)
// if user == nil {
// return errors.New("Not logged in")
// }
// // if user == nil {
// // return errors.New("Not logged in")
// // }
// likeable.Like(user.ID)
// // likeable.Like(user.ID)
// Call OnLike if the object implements it
// receiver, ok := likeable.(LikeEventReceiver)
// // Call OnLike if the object implements it
// // receiver, ok := likeable.(LikeEventReceiver)
// if ok {
// receiver.OnLike(user)
// }
// // if ok {
// // receiver.OnLike(user)
// // }
likeable.Save()
return obj, nil, true
})
// likeable.Save()
// return obj, nil, true
// })
app.Post("/graphql", api.Handler())
}

View File

@ -16,7 +16,7 @@ func main() {
if anime == nil {
color.Yellow(episode.AnimeID)
episode.Delete()
_ = episode.Delete()
count++
}
}