1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-06 19:29:15 +08:00
Dejan Mijić f449f8b9c8
NOISSUE - Fix Content-Type header check (#238)
* Remove charset from required content type

Signed-off-by: Dejan Mijic <dejan@mainflux.com>

* Bump version to 0.2.1

Signed-off-by: Dejan Mijic <dejan@mainflux.com>

* Move constant to transport.go

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
2018-04-22 16:48:06 +02:00

209 lines
3.2 KiB
Go

package api
import (
"fmt"
"net/http"
"github.com/mainflux/mainflux/manager"
)
type apiRes interface {
code() int
headers() map[string]string
empty() bool
}
type identityRes struct {
id string
}
func (res identityRes) headers() map[string]string {
return map[string]string{
"X-client-id": res.id,
}
}
func (res identityRes) code() int {
return http.StatusOK
}
func (res identityRes) empty() bool {
return true
}
type tokenRes struct {
Token string `json:"token,omitempty"`
}
func (res tokenRes) code() int {
return http.StatusCreated
}
func (res tokenRes) headers() map[string]string {
return map[string]string{}
}
func (res tokenRes) empty() bool {
return res.Token == ""
}
type removeRes struct{}
func (res removeRes) code() int {
return http.StatusNoContent
}
func (res removeRes) headers() map[string]string {
return map[string]string{}
}
func (res removeRes) empty() bool {
return true
}
type clientRes struct {
id string
created bool
}
func (res clientRes) code() int {
if res.created {
return http.StatusCreated
}
return http.StatusOK
}
func (res clientRes) headers() map[string]string {
if res.created {
return map[string]string{
"Location": fmt.Sprint("/clients/", res.id),
}
}
return map[string]string{}
}
func (res clientRes) empty() bool {
return true
}
type viewClientRes struct {
manager.Client
}
func (res viewClientRes) code() int {
return http.StatusOK
}
func (res viewClientRes) headers() map[string]string {
return map[string]string{}
}
func (res viewClientRes) empty() bool {
return false
}
type listClientsRes struct {
Clients []manager.Client `json:"clients"`
}
func (res listClientsRes) code() int {
return http.StatusOK
}
func (res listClientsRes) headers() map[string]string {
return map[string]string{}
}
func (res listClientsRes) empty() bool {
return false
}
type channelRes struct {
id string
created bool
}
func (res channelRes) code() int {
if res.created {
return http.StatusCreated
}
return http.StatusOK
}
func (res channelRes) headers() map[string]string {
if res.created {
return map[string]string{
"Location": fmt.Sprint("/channels/", res.id),
}
}
return map[string]string{}
}
func (res channelRes) empty() bool {
return true
}
type viewChannelRes struct {
manager.Channel
}
func (res viewChannelRes) code() int {
return http.StatusOK
}
func (res viewChannelRes) headers() map[string]string {
return map[string]string{}
}
func (res viewChannelRes) empty() bool {
return false
}
type listChannelsRes struct {
Channels []manager.Channel `json:"channels"`
}
func (res listChannelsRes) code() int {
return http.StatusOK
}
func (res listChannelsRes) headers() map[string]string {
return map[string]string{}
}
func (res listChannelsRes) empty() bool {
return false
}
type connectionRes struct{}
func (res connectionRes) code() int {
return http.StatusOK
}
func (res connectionRes) headers() map[string]string {
return map[string]string{}
}
func (res connectionRes) empty() bool {
return true
}
type disconnectionRes struct{}
func (res disconnectionRes) code() int {
return http.StatusNoContent
}
func (res disconnectionRes) headers() map[string]string {
return map[string]string{}
}
func (res disconnectionRes) empty() bool {
return true
}