Add Access Tokens UI

This commit is contained in:
binwiederhier 2023-01-27 23:10:59 -05:00
parent 62140ec001
commit 16c14bf709
19 changed files with 643 additions and 132 deletions

View file

@ -1,6 +1,7 @@
package util
import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
@ -310,7 +311,7 @@ func UnmarshalJSON[T any](body io.ReadCloser) (*T, error) {
}
// UnmarshalJSONWithLimit reads the given io.ReadCloser into a struct, but only until limit is reached
func UnmarshalJSONWithLimit[T any](r io.ReadCloser, limit int) (*T, error) {
func UnmarshalJSONWithLimit[T any](r io.ReadCloser, limit int, allowEmpty bool) (*T, error) {
defer r.Close()
p, err := Peek(r, limit)
if err != nil {
@ -319,7 +320,9 @@ func UnmarshalJSONWithLimit[T any](r io.ReadCloser, limit int) (*T, error) {
return nil, ErrTooLargeJSON
}
var obj T
if err := json.NewDecoder(p).Decode(&obj); err != nil {
if len(bytes.TrimSpace(p.PeekedBytes)) == 0 && allowEmpty {
return &obj, nil
} else if err := json.NewDecoder(p).Decode(&obj); err != nil {
return nil, ErrUnmarshalJSON
}
return &obj, nil
@ -357,3 +360,8 @@ func String(v string) *string {
func Int(v int) *int {
return &v
}
// Time turns a time.Time into a pointer
func Time(v time.Time) *time.Time {
return &v
}