Skip to content

sibelephant/go-web-mock-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Web Server

A simple web server built with Go that demonstrates basic web functionality including static file serving, form handling, and API endpoints.

Features

  • Static file serving
  • Form handling with POST requests
  • Simple API endpoint (/hello)
  • Basic error handling

Project Structure

.
├── main.go           # Main server code
├── static/           # Static files directory
│   ├── index.html    # Landing page
│   └── form.html     # Form page
└── go.mod           # Go module file

Prerequisites

  • Go 1.x or higher
  • Basic understanding of Go and web development

Installation

  1. Clone the repository:
git clone <your-repository-url>
cd Go-webserver
  1. Install dependencies:
go mod tidy

Running the Server

  1. Start the server:
go run main.go
  1. The server will start on port 8080. You can access it at:

API Endpoints

  • GET /: Serves static files from the static directory
  • POST /form: Handles form submissions
    • Accepts form data with fields:
      • name
      • address
  • GET /hello: Returns a simple "hello!" message

Form Usage

  1. Navigate to http://localhost:8080/form.html
  2. Fill in the form fields:
    • Name
    • Address
  3. Submit the form
  4. The server will respond with the submitted data

Error Handling

The server includes basic error handling for:

  • 404 Not Found errors
  • Invalid HTTP methods
  • Form parsing errors

Contributing

Feel free to submit issues and enhancement requests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors