An atproto PDS written in Go
1package helpers 2 3import ( 4 "math/rand" 5 6 "github.com/labstack/echo/v4" 7) 8 9var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") 10 11func InputError(e echo.Context, custom *string) error { 12 msg := "InvalidRequest" 13 if custom != nil { 14 msg = *custom 15 } 16 return genericError(e, 400, msg) 17} 18 19func ServerError(e echo.Context, suffix *string) error { 20 msg := "Internal server error" 21 if suffix != nil { 22 msg += ". " + *suffix 23 } 24 return genericError(e, 400, msg) 25} 26 27func genericError(e echo.Context, code int, msg string) error { 28 return e.JSON(code, map[string]string{ 29 "error": msg, 30 }) 31} 32 33func RandomVarchar(length int) string { 34 b := make([]rune, length) 35 for i := range b { 36 b[i] = letters[rand.Intn(len(letters))] 37 } 38 return string(b) 39}