Skip to content

Commit

Permalink
Merge pull request #1 from gominima/final-fixes
Browse files Browse the repository at this point in the history
Fixed a lot of stuff
  • Loading branch information
apoorvcodes authored Feb 2, 2022
2 parents 0abbedd + 6f53c73 commit d8ce297
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Shubhaankar-Sharma
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATES/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]: Go-requests unexpected behaviour"
labels: "\U0001F41Bbug"
assignees: megatank58, apoorvcodes, Shubhaankar-Sharma

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '38 12 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#53143F",
"titleBar.activeBackground": "#741C58",
"titleBar.activeForeground": "#FEFCFD"
}
}
93 changes: 91 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,92 @@
# go-requests
<p align="center">
<a href="https://gominima.studio">
<img alt="go-requests" src="./assets/logo.png" />
</a>
</p>

[![GoDoc](https://godoc.org/github.com/Shubhaankar-sharma/go-requests?status.svg)](https://godoc.org/github.com/Shubhaankar-sharma/go-requests)
<p align="center">
<a href="https://goreportcard.com/badge/github.com/gominima/go-requests"> <img src="https://goreportcard.com/badge/github.com/gominima/go-requests" /> </a>
<a href="https://img.shields.io/github/go-mod/go-version/gominima/go-requests"> <img src="https://img.shields.io/github/go-mod/go-version/gominima/go-requests" /></a>
<a href="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat"> <img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat" /></a>
<a href="https://discord.gg/gRyCr5APmg"> <img src="https://img.shields.io/discord/916969864512548904" /></a>
<img src="https://img.shields.io/tokei/lines/github/gominima/go-requests" />
<img src="https://img.shields.io/github/languages/code-size/gominima/go-requests" />
</p>

## 🦄 Example

```go
package main

import (
"fmt"
"github.com/gominima/go-requests"
)

func main() {
client := requests.NewRequest("https://random-data-api.com/api/users/random_user", make(map[string]interface{}), make(map[string]string))
res, err := client.Get()
if err != nil {
panic(err)
}
fmt.Println(res.Body)
//response would be something like this
/*
{
"id": 5105,
"uid": "58718d5d-456f-45ac-ac0a-fbda86892afd",
"password": "RyhWmkV0TH",
"first_name": "Bart",
"last_name": "Brekke",
"username": "bart.brekke",
"email": "[email protected]",
"avatar": "https://robohash.org/quaeratipsumiste.png?size=300x300&set=set1",
"gender": "Non-binary",
"phone_number": "+1-268 1-580-929-3581",
"social_insurance_number": "355857970",
"date_of_birth": "1982-09-08",
"employment": {
"title": "Community-Services Planner",
"key_skill": "Organisation"
},
"address": {
"city": "Hyattside",
"street_name": "Erdman Loop",
"street_address": "93982 Frederick Lake",
"zip_code": "86334",
"state": "West Virginia",
"country": "United States",
"coordinates": {
"lat": -82.88119017206014,
"lng": 150.2430514904285
}
},
"credit_card": {
"cc_number": "4198-3576-9309-1264"
},
"subscription": {
"plan": "Bronze",
"status": "Idle",
"payment_method": "Bitcoins",
"term": "Monthly"
}
}
**/
}


```

## ❓Why Go-requests

Go requests is made for making data fetch wat easier and fun to use, it uses all standard go packages without any other dependency, also is pretty fast and reliable .

<br/>

## ⭐ Contributing

**If you wanna help grow this project or say a thank you!**

1. Give minima a [GitHub star](https://github.com/gominima/go-requests/stargazers)
2. Fork requests and Contribute
4. Join our [Discord](https://discord.gg/gRyCr5APmg) community
57 changes: 57 additions & 0 deletions _example/fetch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"fmt"
"github.com/gominima/go-requests"
)

func main() {
client := requests.NewRequest("https://random-data-api.com/api/users/random_user", make(map[string]interface{}), make(map[string]string))
res, err := client.Get()
if err != nil {
panic(err)
}
fmt.Println(res.Body)
//response would be something like this
/*
{
"id": 5105,
"uid": "58718d5d-456f-45ac-ac0a-fbda86892afd",
"password": "RyhWmkV0TH",
"first_name": "Bart",
"last_name": "Brekke",
"username": "bart.brekke",
"email": "[email protected]",
"avatar": "https://robohash.org/quaeratipsumiste.png?size=300x300&set=set1",
"gender": "Non-binary",
"phone_number": "+1-268 1-580-929-3581",
"social_insurance_number": "355857970",
"date_of_birth": "1982-09-08",
"employment": {
"title": "Community-Services Planner",
"key_skill": "Organisation"
},
"address": {
"city": "Hyattside",
"street_name": "Erdman Loop",
"street_address": "93982 Frederick Lake",
"zip_code": "86334",
"state": "West Virginia",
"country": "United States",
"coordinates": {
"lat": -82.88119017206014,
"lng": 150.2430514904285
}
},
"credit_card": {
"cc_number": "4198-3576-9309-1264"
},
"subscription": {
"plan": "Bronze",
"status": "Idle",
"payment_method": "Bitcoins",
"term": "Monthly"
}
}
**/
}
95 changes: 89 additions & 6 deletions app.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package requests

//check
import (
"bytes"
"encoding/json"
"net/http"
//"net/url"
)

type Request struct {
Url string
URL string
Data map[string]interface{}
Headers map[string]string
}
Expand All @@ -20,11 +18,44 @@ type Response struct {
Body map[string]interface{}
}

func NewRequest(url string, data map[string]interface{}, headers map[string]string) *Request {
return &Request{
URL: url,
Data: data,
Headers: headers,
}
}
func (r *Request) Post() (Response, error) {
postBody, _ := json.Marshal(r.Data)
responseBody := bytes.NewBuffer(postBody)
//resp, err := http.Post(r.Url, r.Headers, responseBody)
req, err := http.NewRequest("POST", r.Url, responseBody)
Body := bytes.NewBuffer(postBody)
req, err := http.NewRequest("POST", r.URL, Body)
if err != nil {
return Response{}, err
}
for key, value := range r.Headers {
req.Header.Set(key, value)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
rawresp, err := client.Do(req)
if err != nil {
return Response{}, err
}
defer rawresp.Body.Close()
response := Response{}
response.Status = rawresp.Status
response.Headers = rawresp.Header
var body map[string]interface{}
json.NewDecoder(rawresp.Body).Decode(&body)
response.Body = body
return response, nil
}

/***/
func (r *Request) Get() (Response, error) {
postBody, _ := json.Marshal(r.Data)
Body := bytes.NewBuffer(postBody)
req, err := http.NewRequest("GET", r.URL, Body)
if err != nil {
return Response{}, err
}
Expand All @@ -46,3 +77,55 @@ func (r *Request) Post() (Response, error) {
response.Body = body
return response, nil
}

func (r *Request) Put() (Response, error) {
postBody, _ := json.Marshal(r.Data)
Body := bytes.NewBuffer(postBody)
req, err := http.NewRequest("PUT", r.URL, Body)
if err != nil {
return Response{}, err
}
for key, value := range r.Headers {
req.Header.Set(key, value)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
rawresp, err := client.Do(req)
if err != nil {
return Response{}, err
}
defer rawresp.Body.Close()
response := Response{}
response.Status = rawresp.Status
response.Headers = rawresp.Header
var body map[string]interface{}
json.NewDecoder(rawresp.Body).Decode(&body)
response.Body = body
return response, nil
}

func (r *Request) Patch() (Response, error) {
postBody, _ := json.Marshal(r.Data)
Body := bytes.NewBuffer(postBody)
req, err := http.NewRequest("PATCH", r.URL, Body)
if err != nil {
return Response{}, err
}
for key, value := range r.Headers {
req.Header.Set(key, value)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
rawresp, err := client.Do(req)
if err != nil {
return Response{}, err
}
defer rawresp.Body.Close()
response := Response{}
response.Status = rawresp.Status
response.Headers = rawresp.Header
var body map[string]interface{}
json.NewDecoder(rawresp.Body).Decode(&body)
response.Body = body
return response, nil
}
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/Shubhaankar-sharma/go-requests
module github.com/gominima/go-requests

go 1.15
go 1.17

0 comments on commit d8ce297

Please sign in to comment.