utils

package
v0.0.0-...-ce538ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenKey = &tokenContextKey{}
)

Functions

func AdminMiddleware

func AdminMiddleware(next http.Handler) http.Handler

func CategorizeCommitDate

func CategorizeCommitDate(date time.Time) string

CategorizeCommitDate は、コミットの日付をカテゴリに分類します。 優先度: Today > This Week > This Month > Q1 Q2 Q3 Q4 > Older

func ComparePassword

func ComparePassword(r, u string) error

func CustomJSONEncoder

func CustomJSONEncoder(v interface{}) (string, error)

func DeleteDir

func DeleteDir(dirName string) error

func DeleteToken

func DeleteToken(key string) error

func ErrorJSONResponse

func ErrorJSONResponse(w http.ResponseWriter, status int, err error)

func GeneratePassword

func GeneratePassword(user *model.User) error

func GenerateToken

func GenerateToken(id string, isAdmin bool) (string, error)

func GenerateULID

func GenerateULID() string

GenerateULID generates a new ULID

func GetCharacterLength

func GetCharacterLength(character string) int

func GetDateOnly

func GetDateOnly() string

func GetDay

func GetDay() string

func GetMorph

func GetMorph(sentence string) (model.MorphResponse, error)

func GetQueryParam

func GetQueryParam(r *http.Request, key string, required bool) (string, error)

func GetToken

func GetToken(key string) (string, error)

func IsDateAfter

func IsDateAfter(date1, date2 time.Time) bool

IsDateAfter は date1 の日付が date2 の日付より後かどうかを判定します。 日付が同じであれば、false.

func IsDateBefore

func IsDateBefore(date1, date2 time.Time) bool

IsDateBefore は date1 の日付が date2 の日付より前かどうかを判定します。 日付が同じであれば、false.

func Iso8601ToDate

func Iso8601ToDate(t string) (time.Time, error)

func JwtMiddleware

func JwtMiddleware(next http.Handler) http.Handler

func LoadImage

func LoadImage(data []byte, fileType string) (image.Image, error)

func LoadPrivateKeyFromEnv

func LoadPrivateKeyFromEnv()

func Logger

func Logger() *slog.Logger

func MakeDir

func MakeDir(dirName string) error

func Md2HTML

func Md2HTML(content string) string

func ParseFields

func ParseFields(fields string) ([]string, error)

func ReadFormFile

func ReadFormFile(r *http.Request) (*bytes.Buffer, string, int64, error)

func Resize

func Resize(data []byte, maxHeight int) (*bytes.Buffer, int64)

func SaveFile

func SaveFile(data []byte, path string, extension string) (string, error)

func SaveToken

func SaveToken(key, token string) error

func SuccessJSONResponse

func SuccessJSONResponse(w http.ResponseWriter, res interface{})

func SuccessJSONResponseWithoutEscape

func SuccessJSONResponseWithoutEscape(w http.ResponseWriter, res interface{})

func URLDecode

func URLDecode(s string) (string, error)

func ValidateFileType

func ValidateFileType(r *http.Request) (string, error)

func ValidateMaxFileSize

func ValidateMaxFileSize(r *http.Request) error

func ValidateToken

func ValidateToken(ctx context.Context, tokenString string) (context.Context, error)

Types

type Token

type Token struct {
	UserID  string
	Exp     time.Time
	IsAdmin bool
}

func ExtractToken

func ExtractToken(ctx context.Context) (Token, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL