26 lines
336 B
Go
26 lines
336 B
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
func userIDFromContext(ctx context.Context) (int64, bool) {
|
|
val := ctx.Value(userIDKey)
|
|
if val == nil {
|
|
return 0, false
|
|
}
|
|
|
|
strID, ok := val.(string)
|
|
if !ok {
|
|
return 0, false
|
|
}
|
|
|
|
id, err := strconv.ParseInt(strID, 10, 64)
|
|
if err != nil {
|
|
return 0, false
|
|
}
|
|
|
|
return id, true
|
|
}
|