You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
package requests |
|
|
|
import ( |
|
"encoding/json" |
|
"net/http" |
|
"reflect" |
|
|
|
"github.com/owncast/owncast/webserver/responses" |
|
log "github.com/sirupsen/logrus" |
|
) |
|
|
|
func RequirePOST(w http.ResponseWriter, r *http.Request) bool { |
|
if r.Method != http.MethodPost { |
|
responses.WriteSimpleResponse(w, false, r.Method+" not supported") |
|
return false |
|
} |
|
|
|
return true |
|
} |
|
|
|
func GetValueFromRequest(w http.ResponseWriter, r *http.Request) (ConfigValue, bool) { |
|
decoder := json.NewDecoder(r.Body) |
|
var configValue ConfigValue |
|
if err := decoder.Decode(&configValue); err != nil { |
|
log.Warnln(err) |
|
responses.WriteSimpleResponse(w, false, "unable to parse new value") |
|
return configValue, false |
|
} |
|
|
|
return configValue, true |
|
} |
|
|
|
func GetValuesFromRequest(w http.ResponseWriter, r *http.Request) ([]ConfigValue, bool) { |
|
var values []ConfigValue |
|
|
|
decoder := json.NewDecoder(r.Body) |
|
var configValue ConfigValue |
|
if err := decoder.Decode(&configValue); err != nil { |
|
responses.WriteSimpleResponse(w, false, "unable to parse array of values") |
|
return values, false |
|
} |
|
|
|
object := reflect.ValueOf(configValue.Value) |
|
|
|
for i := 0; i < object.Len(); i++ { |
|
values = append(values, ConfigValue{Value: object.Index(i).Interface()}) |
|
} |
|
|
|
return values, true |
|
}
|
|
|