Skip to content

Commit

Permalink
added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sundaram2021 committed Oct 4, 2024
1 parent 97e1645 commit 5f06146
Show file tree
Hide file tree
Showing 18 changed files with 1,395 additions and 176 deletions.
27 changes: 27 additions & 0 deletions bookstore-api/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Books Api

## Routes
1. GET /books
2. GET /books/:id
3. POST /books
4. PUT /books/:id
5. DELETE /books/:id

## Middlewares
1. auth using Bearer Token
2. admin

## Pkg Used
1. Gin
2. Gin-Sessions
3. Gin-Cookies
4. Go-Std Lib
5. jwt-go

## Database
- Postgres (Docker)

## Swagger Documentation
- using [go-swagger](https://goswagger.io/go-swagger/)

## Profiling docs [here](./profilingdocs.md)
59 changes: 59 additions & 0 deletions chatapp/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Project Documentation: WebSocket Chat Application with Multiple Rooms

This project is a real-time chat application built using Go, WebSockets, and HTML/CSS. It allows users to join chat rooms via unique room IDs and communicate with others in the same room. Below are the key components and features of the application:

---

## **Features**

1. **Multiple Chat Rooms**: Users can create or join chat rooms using unique room IDs. Each room operates independently, ensuring messages are only shared among users in the same room.

2. **User Interface Improvements**: The `join.html` and `interface.html` pages have been enhanced with modern CSS to provide a more user-friendly experience.

3. **User Notifications**: When a new user joins or leaves a room, the application sends a system message to all users in that room to notify them of the change.

4. **Active Rooms Display**: The home page lists all active rooms, showing users which rooms are currently in use. However, users must enter the room ID manually to join; direct links are not provided to prevent unauthorized access.

5. **WebSocket Communication**: Real-time messaging is implemented using WebSockets, allowing for instantaneous communication between clients and the server.

6. **Server-Side Room Management**: The server maintains a mapping of rooms and connected clients, ensuring that messages are routed correctly and that resources are managed efficiently.

7. **Client-Side Storage**: Usernames and room IDs are stored in `localStorage` to persist user data across sessions.


---

## **Getting Started**

- **Running the Server**: Use `go run main.go` to start the server. Ensure that all HTML, CSS, and JavaScript files are correctly placed in the `public` directory.

- **Accessing the Application**: Navigate to `http://localhost:8080/` in your web browser to access the chat application's home page.

- **Joining a Room**: Enter your username and a room ID on the home page to join or create a chat room.

---

## **Project Structure**

- **main.go**: The main server file containing the Go code for handling WebSocket connections, message broadcasting, and room management.

- **public/**: Directory containing all static files served to the client, including HTML pages and CSS styles.

- **join.html**: The home page where users enter their username and room ID.

- **interface.html**: The chat interface displayed after joining a room.

- **static/styles.css**: CSS file containing styles for the application's UI.

---

## **Technologies Used**

- **Go**: Backend language used for server-side logic and WebSocket handling.

- **HTML/CSS**: Frontend technologies for structuring and styling the user interface.

- **JavaScript**: Client-side scripting for WebSocket communication and dynamic content updates.

---

76 changes: 76 additions & 0 deletions databasecrud/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Project Documentation: Go SQLite CRUD Application with Context Support

This project is a Go application that demonstrates how to perform basic CRUD (Create, Read, Update, Delete) operations on a SQLite database using the `database/sql` package and the `modernc.org/sqlite` driver. It showcases the use of `context.Context` to manage database query timeouts and cancellations.

---

## **Features**

1. **Database Connection**: Establishes a connection to a SQLite database file (`names.db`) using the `modernc.org/sqlite` driver.
2. Database ops [here](./databaseops.md)

3. **Listing SQL Drivers**: Outputs all registered SQL drivers available in the Go environment.

4. **CRUD Operations**:
- **Create**: Inserts new records into the `names` table.
- **Read**: Queries and retrieves all records from the `names` table.
- **Update**: Modifies existing records in the `names` table.
- **Delete**: Removes records from the `names` table.

5. **Context Usage**: Utilizes `context.Context` with a timeout for database operations, allowing for better control over query execution times.

6. **Error Handling**: Implements basic error handling and logging to track and display errors during database interactions.

---

## **Getting Started**

- **Prerequisites**:
- Go installed (version 1.13 or higher).
- SQLite installed (optional, for managing the database directly).
- Set up your `GOPATH` and environment variables.

- **Dependencies**:
- Install the SQLite driver for Go:
```sh
go get modernc.org/sqlite
```

- **Database Setup**:
- Create a SQLite database file named `names.db`.
- Create a `names` table with the following SQL command:
```sql
CREATE TABLE names (id INTEGER PRIMARY KEY, name TEXT);
```

- **Running the Application**:
- Execute the program using:
```sh
go run main.go
```
- The application will perform the following actions:
- List available SQL drivers.
- Open the database connection.
- Insert a new user (`Id: 6, Name: "John"`).
- Update the user's name to `"Johnny"`.
- Delete the user.
- Query and print all users in the database.
---
## **Project Structure**
- **main.go**: The main Go file containing all the code for database operations, including functions for listing drivers, opening the database, and performing CRUD operations with context support.
---
## **Technologies Used**
- **Go**: Programming language used to build the application.
- **SQLite**: Lightweight, file-based SQL database for data storage.
- **modernc.org/sqlite**: Pure Go SQLite driver for the `database/sql` package.
---
73 changes: 73 additions & 0 deletions fileserver/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Project Documentation: Go Application for JSON File CRUD Operations

This project is a Go application that performs basic CRUD (Create, Read, Update, Delete) operations on a JSON file named `person.json`. It demonstrates how to work with JSON data and file I/O in Go.

---

## **Features**

1. **Data Structure**:
- Defines a `Person` struct with `Name` (string) and `Age` (uint) fields.

2. **Create Data**:
- Function `CreateData(a []Person)`:
- Creates a new JSON file `person.json`.
- Writes an array of `Person` structs to the file in JSON format.

3. **Read Data**:
- Function `ReadData()`:
- Opens and reads the `person.json` file.
- Outputs the JSON content to the console.

4. **Update Data**:
- Function `UpdateData(a []Person)`:
- Opens `person.json` in write mode.
- Overwrites the existing content with new JSON data from an array of `Person` structs.

5. **Delete Data**:
- Function `DeletData()`:
- Deletes the `person.json` file from the filesystem.

6. **Main Execution Flow**:
- Creates initial data with two `Person` entries and writes to `person.json`.
- Reads and displays the file content.
- Updates the data with a new set of `Person` entries.
- Reads and displays the updated file content.
- Deletes the `person.json` file.

---

## **How to Run**

1. **Prerequisites**:
- Install Go (version 1.13 or higher).

2. **Setup**:
- Save the provided code in a file named `main.go`.

3. **Running the Application**:
- Open a terminal and navigate to the directory containing `main.go`.
- Execute the command:
```sh
go run main.go
```
- The application will perform the following steps:
- Create `person.json` with initial data.
- Read and display the content of `person.json`.
- Update `person.json` with new data.
- Read and display the updated content.
- Delete `person.json`.

4. **Expected Output**:
- Messages indicating the success or failure of each operation.
- The content of `person.json` before and after the update.

---

## **Technologies Used**

- **JSON Encoding/Decoding**: Utilizes Go's `encoding/json` package to marshal and unmarshal data.
- **File I/O Operations**: Uses Go's `os` and `io` packages for file handling.
- **Standard Library**: No external dependencies required.

---
84 changes: 84 additions & 0 deletions gin-server/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Project Documentation: RESTful API for Recipes and Orders using Go and Gin

This project is a Go application that implements a RESTful API for managing recipes and customer orders. It uses the Gin web framework to handle HTTP requests and responses.

---

## **Features**

1. **Recipes Endpoint**:
- **`GET /recipes`**: Retrieves a list of recipes from a `recipes.json` file. Each recipe includes the item name, recipe details, and price.

2. **Orders Management**:
- **`POST /orders`**: Creates a new order by accepting a list of item names and calculates the total price based on the recipes.
- **`PUT /orders`**: Updates an existing order. (Currently, it functions the same as creating an order.)
- **`DELETE /orders/:item`**: Deletes a specific item from the order and recalculates the total price.
- **`GET /orders`**: Retrieves the current order details. (Note: This function may need further implementation as it returns a nil order.)

3. **Welcome Message**:
- **`GET /`**: Returns a welcome message indicating that the Recipes API is active.

---

## **How to Run**

1. **Prerequisites**:
- Install Go (version 1.13 or higher).
- Install the Gin web framework:
```sh
go get -u github.com/gin-gonic/gin
```

2. **Setup**:
- Ensure you have a `recipes.json` file in the same directory as `main.go`. This file should contain an array of `MenuItem` objects with `item`, `recipe`, and `price` fields. Example:
```json
[
{
"item": "Pizza",
"recipe": "Dough, Tomato Sauce, Cheese",
"price": 12.99
},
{
"item": "Burger",
"recipe": "Bun, Patty, Lettuce, Tomato",
"price": 9.99
}
]
```

3. **Running the Application**:
- Execute the application using:
```sh
go run main.go
```
- The server will start on port `8080` and display:
```
server is running on port 8080...
```

4. **Testing the API**:
- Use `curl`, Postman, or any HTTP client to interact with the API endpoints.
- **Example Requests**:
- **Get Recipes**:
```sh
curl http://localhost:8080/recipes
```
- **Create Order**:
```sh
curl -X POST http://localhost:8080/orders -H "Content-Type: application/json" -d '{"orders":["Pizza","Burger"]}'
```
- **Delete Item from Order**:
```sh
curl -X DELETE http://localhost:8080/orders/Pizza
```

---

## **Technologies Used**

- **Go Programming Language**: Core language used for application development.
- **Gin Web Framework**: Used for handling HTTP requests and routing.
- **JSON**: Data format for input/output, using Go's `encoding/json` package.
- **File I/O**: Reading from `recipes.json` using Go's `io/ioutil` and `os` packages.

---
Loading

0 comments on commit 5f06146

Please sign in to comment.