latest cdbcd03

http.go RawHistoryFolder

1package handler
2
3import (
4	"bytes"
5	"encoding/json"
6	"fmt"
7	"io"
8	"net/http"
9
10	"github.com/bnema/gordon/internal/cli"
11	"github.com/bnema/gordon/internal/common"
12)
13
14// PrepareJSONPayload marshals the payload into JSON
15func PrepareJSONPayload(payload common.Payload) ([]byte, error) {
16	return json.Marshal(payload)
17}
18
19// CreateNewRequest creates a new HTTP request
20func CreateNewRequest(method, url string, body []byte) (*http.Request, error) {
21
22	return http.NewRequest(method, url, bytes.NewBuffer(body))
23}
24
25// SetRequestHeaders sets the headers for the request
26func SetRequestHeaders(req *http.Request, token string) {
27	req.Header.Set("Content-Type", "application/json")
28	req.Header.Set("Authorization", "Bearer "+token)
29}
30
31// SendRequest sends the HTTP request and returns the response
32func SendRequest(req *http.Request) (*http.Response, error) {
33	client := &http.Client{}
34	return client.Do(req)
35}
36
37type Response struct {
38	Body []byte
39}
40
41// SendHTTPRequest sends the HTTP request
42func SendHTTPRequest(a *cli.App, rp *common.RequestPayload, method string, endpoint string) (*Response, error) {
43	apiUrl := a.Config.Http.BackendURL + "/api"
44	token := a.Config.General.Token
45
46	fmt.Printf("Final url:", apiUrl+endpoint)
47
48	// Prepare the entire RequestPayload, not just the inner Payload
49	jsonPayload, err := json.Marshal(rp)
50	if err != nil {
51		return nil, fmt.Errorf("failed to marshal payload: %w", err)
52	}
53	// Create a new request
54	req, err := CreateNewRequest(method, apiUrl+endpoint, jsonPayload)
55	if err != nil {
56		return nil, fmt.Errorf("failed to create new request: %w", err)
57	}
58	// Set the request headers
59	SetRequestHeaders(req, token)
60
61	// Send the request
62	resp, err := SendRequest(req)
63	if err != nil {
64		return nil, fmt.Errorf("failed to send request: %w", err)
65	}
66	defer resp.Body.Close()
67
68	// Read the response body
69	body, err := io.ReadAll(resp.Body)
70	if err != nil {
71		return nil, fmt.Errorf("failed to read response body: %w", err)
72	}
73	return &Response{Body: body}, nil
74}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close