Skip to content

Instantly share code, notes, and snippets.

View JakeTheCorn's full-sized avatar

Jake Corn JakeTheCorn

  • Indianapolis, IN
View GitHub Profile
(function() {
'use strict';
angular.module('app')
.provider('AppExampleService', AppExampleServiceProvider);
function AppExampleServiceProvider() {
var state = {};
@JakeTheCorn
JakeTheCorn / post_example.go
Created July 13, 2018 17:39
Post Json in Golang
func createFriend() {
requestURL := "http://rest.learncode.academy/api/johnbob/friends"
payload := strings.NewReader("{\"FirstName\": \"Billy\"}")
req, _ := http.NewRequest("POST", requestURL, payload)
req.Header.Add("content-type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
@JakeTheCorn
JakeTheCorn / get_example.go
Created July 13, 2018 17:39
How to fetch JSON in Go
func getFriends() {
resp, err := http.Get("http://rest.learncode.academy/api/johnbob/friends")
if err != nil {
panic(err)
}
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
stringBody := string(bytes)
@JakeTheCorn
JakeTheCorn / put_example.go
Created July 14, 2018 03:17
Put Example in Golang
func putFriend() {
resourceURL := "http://rest.learncode.academy/api/johnbob/friends/5b496ac679f71d000f953faa"
payload := strings.NewReader("{\"FirstName\": \"Bob\"}")
req, err := http.NewRequest("PUT", resourceURL, payload)
if err != nil {
panic(err)
}
req.Header.Add("content-type", "application/json")
@JakeTheCorn
JakeTheCorn / delete_example.go
Created July 14, 2018 03:23
DELETE example in Go
func destroyFriend() {
resourceURL := "http://rest.learncode.academy/api/johnbob/friends/5b496c3b79f71d000f953fac"
req, err := http.NewRequest("DELETE", resourceURL, nil)
if err != nil {
panic(err)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
@JakeTheCorn
JakeTheCorn / removeItemFromSlice.go
Created July 14, 2018 04:44
Remove Item from Slice in Go
func (cg *ColorGroup) removeColor(colorToRemove string) (int, error) {
colorRemoved := false
for i, c := range cg.Colors {
if colorToRemove == c {
cg.Colors = append(cg.Colors[:i], cg.Colors[i+1:]...)
colorRemoved = true
}
}
if colorRemoved {
return 0, nil
@JakeTheCorn
JakeTheCorn / addItemToSlice.go
Created July 14, 2018 04:46
Add Item to Slice in Go
func (cg *ColorGroup) addColor(newColor string) {
cg.Colors = append(cg.Colors, newColor)
}
@JakeTheCorn
JakeTheCorn / toJSONString.go
Created July 14, 2018 04:51
To Json String
func (cg *ColorGroup) toJSONString() (string, error) {
b, err := json.Marshal(cg)
return string(b), err
}
func (cg *ColorGroup) toJSON() ([]byte, error) {
return json.Marshal(cg)
}
@JakeTheCorn
JakeTheCorn / read_input.go
Created July 14, 2018 15:31
How to read input with the standard library in Go
func main() {
input := readInput()
fmt.Print(input)
}
func readInput() string {
input := ""
fmt.Scanln(&input)
return input
}