This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular.module('app') | |
.provider('AppExampleService', AppExampleServiceProvider); | |
function AppExampleServiceProvider() { | |
var state = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cg *ColorGroup) addColor(newColor string) { | |
cg.Colors = append(cg.Colors, newColor) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cg *ColorGroup) toJSONString() (string, error) { | |
b, err := json.Marshal(cg) | |
return string(b), err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (cg *ColorGroup) toJSON() ([]byte, error) { | |
return json.Marshal(cg) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
input := readInput() | |
fmt.Print(input) | |
} | |
func readInput() string { | |
input := "" | |
fmt.Scanln(&input) | |
return input | |
} |