https://github.com/ilyaumanets/learning_go
https://github.com/ilyaumanets/learning_go
golang rest-api
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ilyaumanets/learning_go
- Owner: IlyaUmanets
- Created: 2020-02-03T17:02:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-07T12:20:57.000Z (over 6 years ago)
- Last Synced: 2025-10-30T06:36:25.820Z (8 months ago)
- Topics: golang, rest-api
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Learning go
## First steps
`First steps` folder includes 6 small scripts I managed using Golang
- even
- geometry
- max
- multithread
- strings
- sum
To run a single script go to `first_steps` folder and run `go run even.go` in example
### Even
Write a function which takes an integer and halves it and returns true if it was even or false if it was odd.
For example half(1) should return (0, false) and half(2) should return (1, true).
### Geometry
Just a plain code to measure perim and area of `rect` and `circle` by using `interface` and `structs`
### Max
Write a function with one variadic parameter that finds the greatest number in a list of numbers.
### Multithread
Just a plain code to print `ping pong` string by using `channels`
### Strings
There are most common `string` fuctions you might use
### Sum
Sum is a function which takes a slice of numbers and adds them together.
What would its function signature look like in Go?
# Rest API
We are building a simple REST-API with Golang a router package called Mux. The main resource we're going to work with is `post`
Go to `rest_api` folder, run `go install`, then run `go run main.go` and use the Postman for testing purposes.
*Available endpoints*
## Create a post
*POST* `http:localhost:8000/posts`
```
{
"title": "yours title",
"body": "yours body text"
}
```
## Get all posts
*GET* `http:localhost:8000/posts`
## Get a single post
*GET* `http:localhost:8000/posts/1`
## Update a single post
*PUT* `http:localhost:8000/posts/1`
```
{
"title": "new awesome title",
"body": "new awesome body"
}
```
## Delete a single post
*DELETE* `http:localhost:8000/posts/1`