├── .gitignore
├── Gopkg.lock
├── Gopkg.toml
├── LICENSE
├── README.md
├── cmd
└── root.go
├── logo.png
└── main.go
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .DS_Store
3 | config.toml
4 | vendor/
5 |
6 | *.exe
7 | *.exe~
8 | *.dll
9 | *.so
10 | *.dylib
11 |
12 | # Test binary, build with `go test -c`
13 | *.test
14 |
15 | # Output of the go coverage tool, specifically when used with LiteIDE
16 | *.out
--------------------------------------------------------------------------------
/Gopkg.lock:
--------------------------------------------------------------------------------
1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2 |
3 |
4 | [[projects]]
5 | name = "github.com/dgrijalva/jwt-go"
6 | packages = ["."]
7 | revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e"
8 | version = "v3.2.0"
9 |
10 | [[projects]]
11 | name = "github.com/fsnotify/fsnotify"
12 | packages = ["."]
13 | revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
14 | version = "v1.4.7"
15 |
16 | [[projects]]
17 | name = "github.com/hashicorp/hcl"
18 | packages = [
19 | ".",
20 | "hcl/ast",
21 | "hcl/parser",
22 | "hcl/printer",
23 | "hcl/scanner",
24 | "hcl/strconv",
25 | "hcl/token",
26 | "json/parser",
27 | "json/scanner",
28 | "json/token"
29 | ]
30 | revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241"
31 | version = "v1.0.0"
32 |
33 | [[projects]]
34 | name = "github.com/inconshreveable/mousetrap"
35 | packages = ["."]
36 | revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
37 | version = "v1.0"
38 |
39 | [[projects]]
40 | name = "github.com/labstack/echo"
41 | packages = [
42 | ".",
43 | "middleware"
44 | ]
45 | revision = "38772c686c76b501f94bd6cd5b77f5842e93b559"
46 | version = "v3.3.10"
47 |
48 | [[projects]]
49 | name = "github.com/labstack/gommon"
50 | packages = [
51 | "bytes",
52 | "color",
53 | "log",
54 | "random"
55 | ]
56 | revision = "ab0bfd9a5eba33a8c364bf3390d809ed23c31f97"
57 | version = "v0.2.9"
58 |
59 | [[projects]]
60 | name = "github.com/magiconair/properties"
61 | packages = ["."]
62 | revision = "de8848e004dd33dc07a2947b3d76f618a7fc7ef1"
63 | version = "v1.8.1"
64 |
65 | [[projects]]
66 | name = "github.com/mattn/go-colorable"
67 | packages = ["."]
68 | revision = "8029fb3788e5a4a9c00e415f586a6d033f5d38b3"
69 | version = "v0.1.2"
70 |
71 | [[projects]]
72 | name = "github.com/mattn/go-isatty"
73 | packages = ["."]
74 | revision = "e1f7b56ace729e4a73a29a6b4fac6cd5fcda7ab3"
75 | version = "v0.0.9"
76 |
77 | [[projects]]
78 | name = "github.com/mitchellh/go-homedir"
79 | packages = ["."]
80 | revision = "af06845cf3004701891bf4fdb884bfe4920b3727"
81 | version = "v1.1.0"
82 |
83 | [[projects]]
84 | name = "github.com/mitchellh/mapstructure"
85 | packages = ["."]
86 | revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe"
87 | version = "v1.1.2"
88 |
89 | [[projects]]
90 | name = "github.com/pelletier/go-toml"
91 | packages = ["."]
92 | revision = "728039f679cbcd4f6a54e080d2219a4c4928c546"
93 | version = "v1.4.0"
94 |
95 | [[projects]]
96 | name = "github.com/spf13/afero"
97 | packages = [
98 | ".",
99 | "mem"
100 | ]
101 | revision = "588a75ec4f32903aa5e39a2619ba6a4631e28424"
102 | version = "v1.2.2"
103 |
104 | [[projects]]
105 | name = "github.com/spf13/cast"
106 | packages = ["."]
107 | revision = "8c9545af88b134710ab1cd196795e7f2388358d7"
108 | version = "v1.3.0"
109 |
110 | [[projects]]
111 | name = "github.com/spf13/cobra"
112 | packages = ["."]
113 | revision = "f2b07da1e2c38d5f12845a4f607e2e1018cbb1f5"
114 | version = "v0.0.5"
115 |
116 | [[projects]]
117 | name = "github.com/spf13/jwalterweatherman"
118 | packages = ["."]
119 | revision = "94f6ae3ed3bceceafa716478c5fbf8d29ca601a1"
120 | version = "v1.1.0"
121 |
122 | [[projects]]
123 | name = "github.com/spf13/pflag"
124 | packages = ["."]
125 | revision = "298182f68c66c05229eb03ac171abe6e309ee79a"
126 | version = "v1.0.3"
127 |
128 | [[projects]]
129 | name = "github.com/spf13/viper"
130 | packages = ["."]
131 | revision = "b5bf975e5823809fb22c7644d008757f78a4259e"
132 | version = "v1.4.0"
133 |
134 | [[projects]]
135 | name = "github.com/valyala/bytebufferpool"
136 | packages = ["."]
137 | revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
138 | version = "v1.0.0"
139 |
140 | [[projects]]
141 | name = "github.com/valyala/fasttemplate"
142 | packages = ["."]
143 | revision = "8b5e4e491ab636663841c42ea3c5a9adebabaf36"
144 | version = "v1.0.1"
145 |
146 | [[projects]]
147 | branch = "master"
148 | name = "golang.org/x/crypto"
149 | packages = [
150 | "acme",
151 | "acme/autocert"
152 | ]
153 | revision = "4def268fd1a49955bfb3dda92fe3db4f924f2285"
154 |
155 | [[projects]]
156 | branch = "master"
157 | name = "golang.org/x/exp"
158 | packages = ["rand"]
159 | revision = "ec7cb31e5a562f5e9e31b300128d2f530f55d127"
160 |
161 | [[projects]]
162 | branch = "master"
163 | name = "golang.org/x/net"
164 | packages = ["idna"]
165 | revision = "74dc4d7220e7acc4e100824340f3e66577424772"
166 |
167 | [[projects]]
168 | branch = "master"
169 | name = "golang.org/x/sys"
170 | packages = ["unix"]
171 | revision = "fde4db37ae7ad8191b03d30d27f258b5291ae4e3"
172 |
173 | [[projects]]
174 | name = "golang.org/x/text"
175 | packages = [
176 | "collate",
177 | "collate/build",
178 | "internal/colltab",
179 | "internal/gen",
180 | "internal/language",
181 | "internal/language/compact",
182 | "internal/tag",
183 | "internal/triegen",
184 | "internal/ucd",
185 | "language",
186 | "secure/bidirule",
187 | "transform",
188 | "unicode/bidi",
189 | "unicode/cldr",
190 | "unicode/norm",
191 | "unicode/rangetable"
192 | ]
193 | revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"
194 | version = "v0.3.2"
195 |
196 | [[projects]]
197 | branch = "master"
198 | name = "gonum.org/v1/gonum"
199 | packages = [
200 | "blas",
201 | "blas/blas64",
202 | "blas/cblas128",
203 | "blas/gonum",
204 | "floats",
205 | "internal/asm/c128",
206 | "internal/asm/c64",
207 | "internal/asm/f32",
208 | "internal/asm/f64",
209 | "internal/cmplx64",
210 | "internal/math32",
211 | "lapack",
212 | "lapack/gonum",
213 | "lapack/lapack64",
214 | "mat",
215 | "mathext",
216 | "mathext/internal/amos",
217 | "mathext/internal/cephes",
218 | "mathext/internal/gonum",
219 | "stat",
220 | "stat/combin",
221 | "stat/distuv"
222 | ]
223 | revision = "01f78999a4cb541c689e949560a86438f0c114d3"
224 |
225 | [[projects]]
226 | name = "gopkg.in/yaml.v2"
227 | packages = ["."]
228 | revision = "51d6538a90f86fe93ac480b35f37b2be17fef232"
229 | version = "v2.2.2"
230 |
231 | [solve-meta]
232 | analyzer-name = "dep"
233 | analyzer-version = 1
234 | inputs-digest = "9403f701f13266cefd97e1e232359e13276647b4a457ec785b89dab8bc76833f"
235 | solver-name = "gps-cdcl"
236 | solver-version = 1
237 |
--------------------------------------------------------------------------------
/Gopkg.toml:
--------------------------------------------------------------------------------
1 | # Gopkg.toml example
2 | #
3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4 | # for detailed Gopkg.toml documentation.
5 | #
6 | # required = ["github.com/user/thing/cmd/thing"]
7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8 | #
9 | # [[constraint]]
10 | # name = "github.com/user/project"
11 | # version = "1.0.0"
12 | #
13 | # [[constraint]]
14 | # name = "github.com/user/project2"
15 | # branch = "dev"
16 | # source = "github.com/myfork/project2"
17 | #
18 | # [[override]]
19 | # name = "github.com/x/y"
20 | # version = "2.4.0"
21 | #
22 | # [prune]
23 | # non-go = false
24 | # go-tests = true
25 | # unused-packages = true
26 |
27 |
28 | [[constraint]]
29 | name = "github.com/labstack/echo"
30 | version = "3.3.10"
31 |
32 | [[constraint]]
33 | name = "github.com/mitchellh/go-homedir"
34 | version = "1.1.0"
35 |
36 | [[constraint]]
37 | name = "github.com/spf13/cobra"
38 | version = "0.0.5"
39 |
40 | [[constraint]]
41 | name = "github.com/spf13/viper"
42 | version = "1.4.0"
43 |
44 | [[constraint]]
45 | branch = "master"
46 | name = "gonum.org/v1/gonum"
47 |
48 | [prune]
49 | go-tests = true
50 | unused-packages = true
51 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Why?
4 |
5 | I mostly do frontend at work, and I've always ignored building error states. Error states are a second class citizen in building UIs. One of the reasons is the developers building it don't get error states often from their APIs. What if we change that?
6 |
7 | ## How?
8 |
9 | rest-in-chaos is a command line utility that spawns proxy server, a really shitty one at that. Every request made to the rest-in-chaos server is either proxied to the passed URL, or returns an error response. It's completely random. It's chaos.
10 |
11 | ## Installation
12 |
13 | Run the following command
14 |
15 | ```
16 | go get -u github.com/nshntarora/rest-in-chaos
17 | ```
18 |
19 | The binary will now be available in the `bin` directory in your `GOPATH`
20 |
21 | ## Usage
22 |
23 | ```
24 | rest-in-chaos <>
25 | ```
26 |
27 | The server will be running on the port **24267**
28 |
29 | ## Example
30 |
31 | ```
32 | rest-in-chaos http://localhost:3000
33 | ```
34 |
35 | Any request to localhost:24267 will be proxied to localhost:3000, with the exception of some requests chosen at random.
36 |
--------------------------------------------------------------------------------
/cmd/root.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2019 NAME HERE
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | package cmd
17 |
18 | import (
19 | "errors"
20 | "fmt"
21 | "os"
22 | "time"
23 |
24 | "github.com/spf13/cobra"
25 |
26 | "math/rand"
27 | "net/http"
28 | "net/url"
29 |
30 | echo "github.com/labstack/echo"
31 | distuv "gonum.org/v1/gonum/stat/distuv"
32 |
33 | middleware "github.com/labstack/echo/middleware"
34 | homedir "github.com/mitchellh/go-homedir"
35 | "github.com/spf13/viper"
36 | )
37 |
38 | var poissonGenerator distuv.Poisson
39 |
40 | var cfgFile string
41 |
42 | // rootCmd represents the base command when called without any subcommands
43 | var rootCmd = &cobra.Command{
44 | Use: "rest-in-chaos",
45 | Short: "add unreliability to any HTTP service",
46 | Long: `rest-in-chaos is an HTTP proxy that randomly fails any request you make to its server, and lets the remaining ones go.
47 | `,
48 | Args: func(cmd *cobra.Command, args []string) error {
49 | if len(args) < 1 {
50 | return errors.New("URL argument required. Run rest-in-chaos <>")
51 | }
52 |
53 | if u, err := url.Parse(args[0]); err != nil || u.Scheme == "" || u.Host == "" {
54 | fmt.Println("WARNING. Just so you know, the URL you've entered does not look right. We're going forward anyway.")
55 | }
56 | return nil
57 | },
58 | Run: func(cmd *cobra.Command, args []string) {
59 |
60 | url, _ := url.Parse(args[0])
61 |
62 | poissonGenerator = distuv.Poisson{
63 | Lambda: 10000,
64 | }
65 |
66 | e := echo.New()
67 | e.Use(middleware.ProxyWithConfig(middleware.ProxyConfig{
68 | Skipper: RequestSkipper,
69 | Balancer: middleware.NewRandomBalancer([]*middleware.ProxyTarget{
70 | {
71 | URL: url,
72 | },
73 | }),
74 | }))
75 | e.GET("/", func(c echo.Context) error {
76 | return c.JSON(GetRandomErrorCode(), nil)
77 | })
78 | e.HideBanner = true
79 | fmt.Println(`
80 | ____ _________________ ____ ________
81 | / __ \/ ____/ ___/_ __/ / _/___ / ____/ /_ ____ _____ _____
82 | / /_/ / __/ \__ \ / / / // __ \ / / / __ \/ __ '/ __ \/ ___/
83 | / _, _/ /___ ___/ // / _/ // / / / / /___/ / / / /_/ / /_/ (__ )
84 | /_/ |_/_____//____//_/ /___/_/ /_/ \____/_/ /_/\__,_/\____/____/
85 |
86 | `)
87 | fmt.Println("Adding unreliability to ", url)
88 | e.Logger.Fatal(e.Start(":24267"))
89 | },
90 | }
91 |
92 | // Execute adds all child commands to the root command and sets flags appropriately.
93 | // This is called by main.main(). It only needs to happen once to the rootCmd.
94 | func Execute() {
95 | if err := rootCmd.Execute(); err != nil {
96 | fmt.Println(err)
97 | os.Exit(1)
98 | }
99 | }
100 |
101 | func RequestSkipper(echo.Context) bool {
102 | if int(poissonGenerator.Rand())%2 == 0 {
103 | fmt.Println(time.Now().Format("15:04:05"), "Received request. Returning Error.")
104 | return true
105 | }
106 | fmt.Println(time.Now().Format("15:04:05"), "Received request. Forwarded.")
107 | return false
108 | }
109 |
110 | func GetRandomErrorCode() int {
111 | failureCodes := []int{http.StatusBadRequest, http.StatusInternalServerError, http.StatusForbidden, http.StatusGatewayTimeout, http.StatusRequestTimeout}
112 |
113 | s := rand.NewSource(time.Now().Unix())
114 | r := rand.New(s) // initialize local pseudorandom generator
115 | return failureCodes[r.Intn(len(failureCodes))]
116 | }
117 |
118 | func init() {
119 | cobra.OnInitialize(initConfig)
120 |
121 | // Here you will define your flags and configuration settings.
122 | // Cobra supports persistent flags, which, if defined here,
123 | // will be global for your application.
124 |
125 | rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.rest-in-chaos.yaml)")
126 |
127 | // Cobra also supports local flags, which will only run
128 | // when this action is called directly.
129 | rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
130 | }
131 |
132 | // initConfig reads in config file and ENV variables if set.
133 | func initConfig() {
134 | if cfgFile != "" {
135 | // Use config file from the flag.
136 | viper.SetConfigFile(cfgFile)
137 | } else {
138 | // Find home directory.
139 | home, err := homedir.Dir()
140 | if err != nil {
141 | fmt.Println(err)
142 | os.Exit(1)
143 | }
144 |
145 | // Search config in home directory with name ".rest-in-chaos" (without extension).
146 | viper.AddConfigPath(home)
147 | viper.SetConfigName(".rest-in-chaos")
148 | }
149 |
150 | viper.AutomaticEnv() // read in environment variables that match
151 |
152 | // If a config file is found, read it in.
153 | if err := viper.ReadInConfig(); err == nil {
154 | fmt.Println("Using config file:", viper.ConfigFileUsed())
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nshntarora/rest-in-chaos/5a8e1d1610ad2d0e37aec5cd9904186dcd69a2ec/logo.png
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2019 NAME HERE
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | package main
17 |
18 | import "github.com/nshntarora/rest-in-chaos/cmd"
19 |
20 | func main() {
21 | cmd.Execute()
22 | }
23 |
--------------------------------------------------------------------------------