-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed Http prefix from all types. - Moved HttpHeader build-related functions to Header Builder type. - Created a JSONErrorBuilder for JSONError building. - Improved Travis-CI to include Go v1.4, v1.5 and latest. - Improved Travis-CI to lint and vet. - Migrated to Coveralls.
- Loading branch information
Showing
14 changed files
with
393 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
language: go | ||
|
||
go: | ||
- 1.4 | ||
- 1.5 | ||
- tip | ||
|
||
before_script: | ||
- go get -u github.com/golang/lint/golint | ||
- go get -u github.com/axw/gocov/gocov | ||
- go get -u github.com/mattn/goveralls | ||
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi | ||
|
||
script: | ||
- go test -v --race ./... | ||
- goveralls -service=travis-ci -repotoken $COVERALLS_TOKEN | ||
|
||
after_script: | ||
- test -z "$(gofmt -s -l -w . | tee /dev/stderr)" | ||
- test -z "$(golint ./... | tee /dev/stderr)" | ||
- go vet ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2016 Fabrício Godoy <skarllot@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
package http | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// A InvalidTokenError represents an error when an invalid or expired token is | ||
// requested. | ||
type InvalidTokenError string | ||
|
||
// Error returns string representation of current instance error. | ||
func (e InvalidTokenError) Error() string { | ||
return fmt.Sprintf( | ||
"The requested token '%s' is invalid or is expired", string(e)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright 2015 Fabrício Godoy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package http | ||
|
||
// A HeaderBuilder provides pre-defined HTTP headers. | ||
type HeaderBuilder int | ||
|
||
// NewHeader creates a new instance of HeaderBuilder. | ||
func NewHeader() HeaderBuilder { | ||
return HeaderBuilder(0) | ||
} | ||
|
||
// AccessControlAllowCredentials creates a HTTP header to CORS-able API indicate | ||
// that authentication is allowed. | ||
func (HeaderBuilder) AccessControlAllowCredentials() *Header { | ||
return &Header{ | ||
"Access-Control-Allow-Credentials", | ||
"", // boolean | ||
} | ||
} | ||
|
||
// AccessControlAllowHeaders creates a HTTP header to CORS-able API indicate | ||
// which HTTP headers are allowed. | ||
func (HeaderBuilder) AccessControlAllowHeaders() *Header { | ||
return &Header{ | ||
"Access-Control-Allow-Headers", | ||
"", // comma-separated list | ||
} | ||
} | ||
|
||
// AccessControlAllowMethods creates a HTTP header to CORS-able API indicate | ||
// which HTTP methods are allowed to current resource. | ||
func (HeaderBuilder) AccessControlAllowMethods() *Header { | ||
return &Header{ | ||
"Access-Control-Allow-Methods", | ||
"", // comma-separated list of HTTP methods | ||
} | ||
} | ||
|
||
// AccessControlAllowOrigin creates a HTTP header to CORS-able API indicate | ||
// which origin is expected. | ||
func (HeaderBuilder) AccessControlAllowOrigin() *Header { | ||
return &Header{ | ||
"Access-Control-Allow-Origin", | ||
"", // http-formatted domain or asterisk to any | ||
} | ||
} | ||
|
||
// AccessControlMaxAge creates a HTTP header to CORS-able API indicate how long | ||
// preflight results should be cached. | ||
func (HeaderBuilder) AccessControlMaxAge() *Header { | ||
return &Header{ | ||
"Access-Control-Max-Age", | ||
"", // seconds | ||
} | ||
} | ||
|
||
// AccessControlRequestHeaders creates a HTTP header to CORS-able client | ||
// indicate which headers will be used for request. | ||
func (HeaderBuilder) AccessControlRequestHeaders() *Header { | ||
return &Header{ | ||
"Access-Control-Request-Headers", | ||
"", // comma-separated list of HTTP headers | ||
} | ||
} | ||
|
||
// AccessControlRequestMethod creates a HTTP header to CORS-able client indicate | ||
// which HTTP method will be used for request. | ||
func (HeaderBuilder) AccessControlRequestMethod() *Header { | ||
return &Header{ | ||
"Access-Control-Request-Method", | ||
"", // HTTP method name | ||
} | ||
} | ||
|
||
// ContentType creates a HTTP header builder to define a content type. | ||
func (HeaderBuilder) ContentType() HeaderContentTypeBuilder { | ||
return HeaderContentTypeBuilder(0) | ||
} | ||
|
||
// Empty creates a empty HTTP header. | ||
func (HeaderBuilder) Empty() *Header { | ||
return &Header{ | ||
"", | ||
"", | ||
} | ||
} | ||
|
||
// Location creates a HTTP header to define location of new object. | ||
func (HeaderBuilder) Location() *Header { | ||
return &Header{ | ||
"Location", | ||
"", // relative http location | ||
} | ||
} | ||
|
||
// Origin creates a HTTP header to CORS-able client indicate its address. | ||
func (HeaderBuilder) Origin() *Header { | ||
return &Header{ | ||
"Origin", | ||
"", // http-formatted domain | ||
} | ||
} | ||
|
||
// A HeaderContentTypeBuilder provides pre-defined Content Types HTTP headers. | ||
type HeaderContentTypeBuilder int | ||
|
||
// Empty creates a HTTP header to undefined content type. | ||
func (HeaderContentTypeBuilder) Empty() *Header { | ||
return &Header{ | ||
"Content-Type", | ||
"", | ||
} | ||
} | ||
|
||
// HTML creates a HTTP header to define HTML content type. | ||
func (HeaderContentTypeBuilder) HTML() *Header { | ||
return HeaderContentTypeBuilder(0). | ||
Empty(). | ||
SetValue("text/html; charset=utf-8") | ||
} | ||
|
||
// JSON creates a HTTP header to define JSON content type. | ||
func (HeaderContentTypeBuilder) JSON() *Header { | ||
return HeaderContentTypeBuilder(0). | ||
Empty(). | ||
SetValue("application/json; charset=utf-8") | ||
} | ||
|
||
// Text creates a HTTP header to define plain text content type. | ||
func (HeaderContentTypeBuilder) Text() *Header { | ||
return HeaderContentTypeBuilder(0). | ||
Empty(). | ||
SetValue("text/plain; charset=utf-8") | ||
} | ||
|
||
// XML creates a HTTP header to define XML content type. | ||
func (HeaderContentTypeBuilder) XML() *Header { | ||
return HeaderContentTypeBuilder(0). | ||
Empty(). | ||
SetValue("application/xml; charset=utf-8") | ||
} |
Oops, something went wrong.