├── .gitignore
├── go.mod
├── .travis.yml
├── README.md
├── gores_test.go
├── gores.go
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | tmp
2 | *.sublime-project
3 | *.sublime-workspace
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/alioygur/gores
2 |
3 | go 1.15
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | install:
4 | - go get github.com/alioygur/gores
5 |
6 | go:
7 | - 1.7.x
8 | - 1.12.x
9 | - 1.13.x
10 | - 1.14.x
11 | - 1.15.x
12 | - tip
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gores
2 |
3 | [](https://travis-ci.org/alioygur/gores)
4 | [](https://godoc.org/github.com/alioygur/gores)
5 | [](https://goreportcard.com/report/github.com/alioygur/gores)
6 |
7 | http response utility library for Go
8 |
9 | this package is very small and lightweight, useful for RESTful APIs.
10 |
11 |
12 | ## installation
13 |
14 | `go get github.com/alioygur/gores`
15 |
16 | ## requirements
17 |
18 | gores library requires Go version `>=1.7`
19 |
20 | ## usage
21 |
22 | ```go
23 | package main
24 |
25 | import (
26 | "log"
27 | "net/http"
28 |
29 | "github.com/alioygur/gores"
30 | )
31 |
32 | type User struct {
33 | Name string
34 | Email string
35 | Age int
36 | }
37 |
38 | func main() {
39 | // Plain text response
40 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
41 | gores.String(w, http.StatusOK, "Hello World")
42 | })
43 |
44 | // HTML response
45 | http.HandleFunc("/html", func(w http.ResponseWriter, r *http.Request) {
46 | gores.HTML(w, http.StatusOK, "
Hello World
")
47 | })
48 |
49 | // JSON response
50 | http.HandleFunc("/json", func(w http.ResponseWriter, r *http.Request) {
51 | user := User{Name: "Ali", Email: "ali@example.com", Age: 28}
52 | gores.JSON(w, http.StatusOK, user)
53 | })
54 |
55 | // File response
56 | http.HandleFunc("/file", func(w http.ResponseWriter, r *http.Request) {
57 | err := gores.File(w, r, "./path/to/file.html")
58 |
59 | if err != nil {
60 | log.Println(err.Error())
61 | }
62 | })
63 |
64 | // Download file
65 | http.HandleFunc("/download-file", func(w http.ResponseWriter, r *http.Request) {
66 | err := gores.Download(w, r, "./path/to/file.pdf", "example.pdf")
67 |
68 | if err != nil {
69 | log.Println(err.Error())
70 | }
71 | })
72 |
73 | // No content
74 | http.HandleFunc("/no-content", func(w http.ResponseWriter, r *http.Request) {
75 | gores.NoContent(w)
76 | })
77 |
78 | // Error response
79 | http.HandleFunc("/error", func(w http.ResponseWriter, r *http.Request) {
80 | gores.Error(w, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
81 | })
82 |
83 | err := http.ListenAndServe(":8000", nil)
84 | if err != nil {
85 | log.Fatal("ListenAndServe: ", err)
86 | }
87 | }
88 | ```
89 |
90 | for more documentation [godoc](https://godoc.org/github.com/alioygur/gores)
91 |
92 | ## Contribute
93 |
94 | **Use issues for everything**
95 |
96 | - Report problems
97 | - Discuss before sending a pull request
98 | - Suggest new features/recipes
99 | - Improve/fix documentation
100 |
101 | ## Thanks & Authors
102 |
103 | I use code/got inspiration from these excellent libraries:
104 |
105 | - [labstack/echo](https://github.com/labstack/echo) micro web framework
106 |
--------------------------------------------------------------------------------
/gores_test.go:
--------------------------------------------------------------------------------
1 | package gores
2 |
3 | import (
4 | "net/http"
5 | "net/http/httptest"
6 | "testing"
7 | )
8 |
9 | type User struct {
10 | Name string
11 | Email string
12 | Age int
13 | }
14 |
15 | var user = User{
16 | Name: "Jhon",
17 | Email: "jhon@example.com",
18 | Age: 20,
19 | }
20 |
21 | func TestHTML(t *testing.T) {
22 | responseString := "Hello World
"
23 | responseCode := http.StatusOK
24 |
25 | resp := httptest.NewRecorder()
26 |
27 | HTML(resp, responseCode, responseString)
28 |
29 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != TextHTMLCharsetUTF8 || resp.Code != responseCode {
30 | t.Fail()
31 | }
32 | }
33 |
34 | func TestString(t *testing.T) {
35 | responseString := "Hello World"
36 | responseCode := http.StatusOK
37 |
38 | resp := httptest.NewRecorder()
39 |
40 | String(resp, responseCode, responseString)
41 |
42 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != TextPlainCharsetUTF8 || resp.Code != responseCode {
43 | t.Fail()
44 | }
45 | }
46 |
47 | func TestJSON(t *testing.T) {
48 |
49 | responseString := `{"Name":"Jhon","Email":"jhon@example.com","Age":20}`
50 | responseCode := http.StatusOK
51 |
52 | resp := httptest.NewRecorder()
53 |
54 | JSON(resp, responseCode, user)
55 |
56 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != ApplicationJSONCharsetUTF8 || resp.Code != responseCode {
57 | t.Fail()
58 | }
59 | }
60 |
61 | func TestJSONIndent(t *testing.T) {
62 |
63 | responseString := `{
64 | **%%"Name": "Jhon",
65 | **%%"Email": "jhon@example.com",
66 | **%%"Age": 20
67 | **}`
68 |
69 | responseCode := http.StatusOK
70 |
71 | resp := httptest.NewRecorder()
72 |
73 | JSONIndent(resp, responseCode, user, "**", "%%")
74 |
75 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != ApplicationJSONCharsetUTF8 || resp.Code != responseCode {
76 | t.Fail()
77 | }
78 | }
79 |
80 | func TestJSONP(t *testing.T) {
81 |
82 | responseString := `parseResponse({"Name":"Jhon","Email":"jhon@example.com","Age":20});`
83 |
84 | responseCode := http.StatusOK
85 |
86 | resp := httptest.NewRecorder()
87 |
88 | JSONP(resp, responseCode, "parseResponse", user)
89 |
90 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != ApplicationJavaScriptCharsetUTF8 || resp.Code != responseCode {
91 | t.Fail()
92 | }
93 | }
94 |
95 | func TestXML(t *testing.T) {
96 |
97 | responseString := `
98 | Jhonjhon@example.com20`
99 |
100 | responseCode := http.StatusOK
101 |
102 | resp := httptest.NewRecorder()
103 |
104 | XML(resp, responseCode, user)
105 |
106 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != ApplicationXMLCharsetUTF8 || resp.Code != responseCode {
107 | t.Fail()
108 | }
109 | }
110 |
111 | func TestXMLIndent(t *testing.T) {
112 |
113 | responseString := `
114 | **
115 | **%%Jhon
116 | **%%jhon@example.com
117 | **%%20
118 | **`
119 |
120 | responseCode := http.StatusOK
121 |
122 | resp := httptest.NewRecorder()
123 |
124 | XMLIndent(resp, responseCode, user, "**", "%%")
125 |
126 | if resp.Body.String() != responseString || resp.Header().Get(ContentType) != ApplicationXMLCharsetUTF8 || resp.Code != responseCode {
127 | t.Fail()
128 | }
129 | }
130 |
131 | func TestNoContent(t *testing.T) {
132 |
133 | responseString := ``
134 |
135 | responseCode := http.StatusNoContent
136 |
137 | resp := httptest.NewRecorder()
138 |
139 | NoContent(resp)
140 |
141 | if resp.Body.String() != responseString || resp.Code != responseCode {
142 | t.Fail()
143 | }
144 | }
145 |
146 | func TestError(t *testing.T) {
147 |
148 | responseString := `error`
149 |
150 | responseCode := http.StatusBadRequest
151 |
152 | resp := httptest.NewRecorder()
153 |
154 | Error(resp, responseCode, responseString)
155 |
156 | if resp.Body.String() != responseString+"\n" || resp.Code != responseCode {
157 | t.Fail()
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/gores.go:
--------------------------------------------------------------------------------
1 | // Package gores http response utility library for GO
2 | package gores
3 |
4 | import (
5 | "encoding/json"
6 | "encoding/xml"
7 | "net/http"
8 | "path/filepath"
9 | )
10 |
11 | // HTTP Methods
12 | const (
13 | CONNECT = "CONNECT"
14 | DELETE = "DELETE"
15 | GET = "GET"
16 | HEAD = "HEAD"
17 | OPTIONS = "OPTIONS"
18 | PATCH = "PATCH"
19 | POST = "POST"
20 | PUT = "PUT"
21 | TRACE = "TRACE"
22 | )
23 |
24 | // Media Types
25 | const (
26 | ApplicationJSON = "application/json"
27 | ApplicationJSONCharsetUTF8 = ApplicationJSON + "; " + CharsetUTF8
28 | ApplicationJavaScript = "application/javascript"
29 | ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8
30 | ApplicationXML = "application/xml"
31 | ApplicationXMLCharsetUTF8 = ApplicationXML + "; " + CharsetUTF8
32 | ApplicationForm = "application/x-www-form-urlencoded"
33 | ApplicationProtobuf = "application/protobuf"
34 | ApplicationMsgpack = "application/msgpack"
35 | TextHTML = "text/html"
36 | TextHTMLCharsetUTF8 = TextHTML + "; " + CharsetUTF8
37 | TextPlain = "text/plain"
38 | TextPlainCharsetUTF8 = TextPlain + "; " + CharsetUTF8
39 | MultipartForm = "multipart/form-data"
40 | )
41 |
42 | // Headers
43 | const (
44 | AcceptEncoding = "Accept-Encoding"
45 | Authorization = "Authorization"
46 | ContentDisposition = "Content-Disposition"
47 | ContentEncoding = "Content-Encoding"
48 | ContentLength = "Content-Length"
49 | ContentType = "Content-Type"
50 | Location = "Location"
51 | Upgrade = "Upgrade"
52 | Vary = "Vary"
53 | WWWAuthenticate = "WWW-Authenticate"
54 | XForwardedFor = "X-Forwarded-For"
55 | XRealIP = "X-Real-IP"
56 | )
57 |
58 | const (
59 | // CharsetUTF8 utf8 character set
60 | CharsetUTF8 = "charset=utf-8"
61 |
62 | // WebSocket web socket protocol
63 | WebSocket = "websocket"
64 | )
65 |
66 | // HTML sends an HTTP response with status code.
67 | func HTML(w http.ResponseWriter, code int, html string) {
68 | w.Header().Set(ContentType, TextHTMLCharsetUTF8)
69 | w.WriteHeader(code)
70 | w.Write([]byte(html))
71 | }
72 |
73 | // String sends a string response with status code.
74 | func String(w http.ResponseWriter, code int, s string) {
75 | w.Header().Set(ContentType, TextPlainCharsetUTF8)
76 | w.WriteHeader(code)
77 | w.Write([]byte(s))
78 | }
79 |
80 | // JSON sends a JSON response with status code.
81 | func JSON(w http.ResponseWriter, code int, i interface{}) error {
82 | b, err := json.Marshal(i)
83 | if err != nil {
84 | return err
85 | }
86 | _json(w, code, b)
87 | return nil
88 | }
89 |
90 | // MustJSON calls JSON and panics on error
91 | func MustJSON(w http.ResponseWriter, code int, i interface{}) {
92 | if err := JSON(w, code, i); err != nil {
93 | panic(err)
94 | }
95 | }
96 |
97 | // JSONIndent sends a JSON response with status code, but it applies prefix and indent to format the output.
98 | func JSONIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string) error {
99 | b, err := json.MarshalIndent(i, prefix, indent)
100 | if err != nil {
101 | return err
102 | }
103 | _json(w, code, b)
104 | return nil
105 | }
106 |
107 | // MustJSONIndent calls JSONIndent and panics on error
108 | func MustJSONIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string) {
109 | if err := JSONIndent(w, code, i, prefix, indent); err != nil {
110 | panic(err)
111 | }
112 | }
113 |
114 | func _json(w http.ResponseWriter, code int, b []byte) {
115 | w.Header().Set(ContentType, ApplicationJSONCharsetUTF8)
116 | w.WriteHeader(code)
117 | w.Write(b)
118 | }
119 |
120 | // JSONP sends a JSONP response with status code. It uses `callback` to construct
121 | // the JSONP payload.
122 | func JSONP(w http.ResponseWriter, code int, callback string, i interface{}) error {
123 | b, err := json.Marshal(i)
124 | if err != nil {
125 | return err
126 | }
127 | w.Header().Set(ContentType, ApplicationJavaScriptCharsetUTF8)
128 | w.WriteHeader(code)
129 | w.Write([]byte(callback + "("))
130 | w.Write(b)
131 | w.Write([]byte(");"))
132 | return nil
133 | }
134 |
135 | // MustJSONP calls JSONP and panics on error
136 | func MustJSONP(w http.ResponseWriter, code int, callback string, i interface{}) {
137 | if err := JSONP(w, code, callback, i); err != nil {
138 | panic(err)
139 | }
140 | }
141 |
142 | // XML sends an XML response with status code.
143 | func XML(w http.ResponseWriter, code int, i interface{}) error {
144 | b, err := xml.Marshal(i)
145 | if err != nil {
146 | return err
147 | }
148 | _xml(w, code, b)
149 | return nil
150 | }
151 |
152 | // MustXML calls XML and panics on error
153 | func MustXML(w http.ResponseWriter, code int, i interface{}) {
154 | if err := XML(w, code, i); err != nil {
155 | panic(err)
156 | }
157 | }
158 |
159 | // XMLIndent sends an XML response with status code, but it applies prefix and indent to format the output.
160 | func XMLIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string) error {
161 | b, err := xml.MarshalIndent(i, prefix, indent)
162 | if err != nil {
163 | return err
164 | }
165 | _xml(w, code, b)
166 | return nil
167 | }
168 |
169 | // MustXMLIndent calls XMLIndent and panics on error
170 | func MustXMLIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string) {
171 | if err := XMLIndent(w, code, i, prefix, indent); err != nil {
172 | panic(err)
173 | }
174 | }
175 |
176 | func _xml(w http.ResponseWriter, code int, b []byte) {
177 | w.Header().Set(ContentType, ApplicationXMLCharsetUTF8)
178 | w.WriteHeader(code)
179 | w.Write([]byte(xml.Header))
180 | w.Write(b)
181 | }
182 |
183 | // File sends a response with the content of the file
184 | func File(w http.ResponseWriter, r *http.Request, path string) error {
185 | return file(w, r, path, "", false)
186 | }
187 |
188 | // MustFile calls File and panics on error
189 | func MustFile(w http.ResponseWriter, r *http.Request, path string) {
190 | if err := File(w, r, path); err != nil {
191 | panic(err)
192 | }
193 | }
194 |
195 | // Download the client is prompted to save the file with provided `name`,
196 | // name can be empty, in that case name of the file is used.
197 | func Download(w http.ResponseWriter, r *http.Request, path string, name string) error {
198 | return file(w, r, path, name, true)
199 | }
200 |
201 | // MustDownload calls Download and panics on error
202 | func MustDownload(w http.ResponseWriter, r *http.Request, path string, name string) {
203 | if err := Download(w, r, path, name); err != nil {
204 | panic(err)
205 | }
206 | }
207 |
208 | func file(w http.ResponseWriter, r *http.Request, path, name string, attachment bool) (err error) {
209 | dir, file := filepath.Split(path)
210 | if attachment {
211 | w.Header().Set(ContentDisposition, "attachment; filename="+name)
212 | }
213 |
214 | fs := http.Dir(dir)
215 | f, err := fs.Open(file)
216 | if err != nil {
217 | return
218 | }
219 | defer f.Close()
220 |
221 | fi, _ := f.Stat()
222 |
223 | http.ServeContent(w, r, fi.Name(), fi.ModTime(), f)
224 |
225 | return
226 | }
227 |
228 | // NoContent sends a response with no body and a status code.
229 | func NoContent(w http.ResponseWriter) {
230 | w.WriteHeader(http.StatusNoContent)
231 | }
232 |
233 | // Error sends a error response with a status code
234 | func Error(w http.ResponseWriter, code int, message string) {
235 | http.Error(w, message, code)
236 | }
237 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------