u/NamelessArab_

how would I set a single item in an array

when I say "set" I mean replace an item that is filtered based of one of its properties

if you dont quite understand heres my situation for clarity

I have a Meme object that is embeded in the savedMemes property array in the each user document

I want to update a specific meme in the savedMemes property array and I have an _id to reference it

I initially tried doing a $pull operation then a $push operation

but when I $pull the meme out the $push operation can no longer find to anyone with the unUpdated meme since he cant reference by its Id because its been pulled out

I looked into trying to use the $set operator but the issue is that all the instruction I can find dont specify how to set an item in an array property thats is filtered based one of its properties

reddit.com
u/NamelessArab_ — 4 days ago
▲ 7 r/golang

any good image validation libs for go

Im making an htmx-go application with the gin framework and in it I use images

since Im using htmx I primarily use forms to send images since its really the only way I know

anyhow how I validate the image type is through this function

func getMemeImageType(header *multipart.FileHeader) (string, error) {
if strings.HasSuffix(header.Filename, ".png") {
return "png", nil
}
if strings.HasSuffix(header.Filename, ".jpg") || strings.HasSuffix(header.Filename, ".jpeg") {
return "jpeg", nil
}
if strings.HasSuffix(header.Filename, ".webp") {
return "webp", nil
}
return "", errors.New("unsupported image format")
}

pretty rough I know

so can you guys recommend a library that can:

A: find the image type of a formFile

B: confirm the file is valid encoding for whatever stated image type it is

C: image resizing capabilities for performance purposes

reddit.com
u/NamelessArab_ — 4 days ago

any good image validation libs for go

Im making an htmx-go application with the gin framework and in it I use images

since Im using htmx I primarily use forms to send images since its really the only way I know

anyhow how I validate the image type is through this function

func getMemeImageType(header *multipart.FileHeader) (string, error) {

`if strings.HasSuffix(header.Filename, ".png") {`

	`return "png", nil`

`}`

`if strings.HasSuffix(header.Filename, ".jpg") || strings.HasSuffix(header.Filename, ".jpeg") {`



	`return "jpeg", nil`

`}`



`if strings.HasSuffix(header.Filename, ".webp") {`

	`return "webp", nil`

`}`

`return "", errors.New("unsupported image format")`

}

pretty rough I know

so can you guys recommend a library that can:

A: find the image type of a formFile

B: confirm the file is valid encoding for whatever stated image type it is

C: image resizing capabilities for performance purposes

reddit.com
u/NamelessArab_ — 5 days ago

so refresh tokens are just session keys?

I have go application that uses `jwt` for authentication

in my app I knew I needed both an accessToken and a refreshToken

but I had only created an accessToken and left the refresh token implementation for later

later has come and so Im little confused on refresh tokens

they are used to refresh your old access token and have 2 reasons they are more secure

-they only need to be accessed from the refresh path making it only accessible on the refresh path increasing security

-it can be revoked unlike the accessToken

the latter confused me because it implies that refresh TOKENS are really just session keys stored in a central db, yet all the implementations I find have it be jwt (which its entire problem is that it cant be revoked because the auth is done with math)

so do I just ignore everybody else and implement it as a session key or am I missing something

reddit.com
u/NamelessArab_ — 24 days ago