summary refs log tree commit diff stats
path: root/src
Commit message (Expand)AuthorAgeFilesLines
* added functionality to update posts v0.2.0Ben Morrison2019-08-301-3/+63
* redundant code removedBen Morrison2019-08-301-3/+0
* delintingBen Morrison2019-08-301-5/+2
* limit number of displayed posts to 30 v0.1.0Ben Morrison2019-08-291-4/+12
* tests in makefile, cleaned db testBen Morrison2019-08-281-1/+1
* db tests are on separate pathBen Morrison2019-08-281-4/+6
* enabled hints for cli args, changed db locationBen Morrison2019-08-281-1/+1
* formatting outputBen Morrison2019-08-281-0/+2
* minor db test - will expand laterBen Morrison2019-08-281-0/+13
* fix logging testBen Morrison2019-08-281-2/+2
* cleanupBen Morrison2019-08-282-35/+2
* made list the default behaviorBen Morrison2019-08-271-6/+4
* formatting outputBen Morrison2019-08-271-0/+1
* minor syntax errorBen Morrison2019-08-271-2/+2
* finished posting and displayBen Morrison2019-08-272-32/+90
* added subtype to db::Cmd. Fleshed out cli args.Ben Morrison2019-08-272-8/+31
* db connected, logging upBen Morrison2019-08-273-3/+85
* fleshing out typesBen Morrison2019-08-272-0/+83
* initBen Morrison2019-08-271-0/+4
highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
// Request manages all outgoing requests for cetus projects.
package request

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"time"
)

// GetRes takes api and params as input and returns the body and
// error.
func GetRes(api string, params map[string]string) (string, error) {
	var body string

	c := http.Client{
		// TODO: timeout should be configurable by the user
		Timeout: time.Second * 64,
	}

	req, err := http.NewRequest(http.MethodGet, api, nil)
	if err != nil {
		err = fmt.Errorf("%s\n%s",
			"request.go: failed to create request",
			err.Error())
		return body, err
	}

	// User-Agent should be passed with every request to make work
	// easier for the server handler. Include contact information
	// along with the project name so they could reach you if
	// required.
	req.Header.Set("User-Agent",
		"Andinus / Cetus - https://andinus.nand.sh/projects/cetus")

	// Params is a simple map[string]string which contains
	// parameters that needs to be passed along with the request.
	// There is no check involved here & it should be done before
	// passing params to this function.
	q := req.URL.Query()
	for k, v := range params {
		q.Add(k, v)
	}
	req.URL.RawQuery = q.Encode()

	res, err := c.Do(req)
	if err != nil {
		err = fmt.Errorf("%s\n%s",
			"request.go: failed to get response",
			err.Error())
		return body, err
	}
	defer res.Body.Close()

	if res.StatusCode != 200 {
		err = fmt.Errorf("Unexpected response status code received: %d %s",
			res.StatusCode,
			http.StatusText(res.StatusCode))
		return body, err
	}

	// This will read everything to memory and is okay to use here
	// because the json response received will be small unlike in
	// download.go (package background) where it is an image.
	out, err := ioutil.ReadAll(res.Body)
	if err != nil {
		err = fmt.Errorf("%s\n%s",
			"request.go: failed to read body to out (var)",
			err.Error())
		return body, err
	}

	body = string(out)
	return body, err
}
commit/TODO?h=v1.5.2&id=636f69d346e31ee59702c814574c1379aa9cb8e6'>636f69d3 ^
d3c262a9 ^
cf8b174e ^
e02d47ed ^
48a8eab5 ^
2e631f44 ^
f3bc52e5 ^
3a917b8a ^
4be8b401 ^



d955e3f0 ^
75013dc7 ^
67bb838c ^
a808a661 ^
bba8d293 ^
2a64495f ^
5e449699 ^
8895b130 ^

7b04e507 ^
87db0130 ^
dd4a4145 ^
8f2f1767 ^
db1721dd ^
b624bd94 ^
83868c7a ^
6099d9a3 ^
9207e83c ^
f7db061b ^
6099d9a3 ^
f3bc52e5 ^
f01ef1a0 ^
6f43de0a ^




fca1fc4f ^
f70ee6b2 ^
0db4c9b2 ^
b2d63ef5 ^
6908d0cc ^
d994d0d6 ^
01c89bb5 ^
c776804d ^
dab4db44 ^
cc4210ff ^
34c131ef ^
32f93303 ^
c1a9373c ^
66c5bb93 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102