This project is a simple HTTP server written in Go. It serves static files and provides basic form handling and API endpoints.
-
simple-http-server-golang/
- static/
- form.html
- main.go
- main_test.go
- go.mod
- go.sum
- README.md
- static/
-
static/: Directory containing static files to be served. -
main.go: Main application file containing the server code. -
main_test.go: Test file for the application. -
go.mod: Go module file. -
go.sum: Go dependencies checksum file. -
README.md: Project documentation.
net/http: Standard library for HTTP client and server implementations.github.com/stretchr/testify: Library for writing unit tests.
-
Clone the repository:
git clone https://github.com/yantology/simple-http-server-golang.git cd simple-http-server-golang -
Install dependencies:
go mod tidy
-
Run the server:
go run main.go
-
Run tests:
go test ./...
-
Build the application:
go build -o simple-http-server.exe
-
Run the built application:
./simple-http-server
The server will start on port 8080. You can access it at http://localhost:8080.
- To access the form, navigate to
http://localhost:8080/form. - To access the hello endpoint, navigate to
http://localhost:8080/api/v1/hello. - To submit the form, use the endpoint
http://localhost:8080/api/v1/form.
You can also run the application using Docker(look dockerfile for the setup).
-
Build the Docker image:
docker build -t simple-http-server . -
Run the Docker container:
docker run -p 8080:8080 simple-http-server
The server will start on port 8080. You can access it at http://localhost:8080.
- To access the form, navigate to
http://localhost:8080/form. - To access the hello endpoint, navigate to
http://localhost:8080/api/v1/hello. - To submit the form, use the endpoint
http://localhost:8080/api/v1/form.
This project is licensed under the MIT License.