Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASCII Art Web Generator

Description

This project is a lightweight, web-based ASCII Art Generator written in Go. It provides a simple browser interface that allows users to type in standard text, select a specific banner style (e.g., standard, shadow, thinkertoy), and instantly view their text converted into stylized ASCII art. The backend handles the routing, form parsing, and template rendering, while relying on a custom generator package for the core ASCII logic.

Usage: How to Run

  • Make sure you have Go installed on your machine.

  • Ensure you have the index.html file in the same directory as your main.go file.

  • Ensure the custom student/generator package is properly set up in your Go workspace or module. Steps to run:

  • Open your terminal and navigate to the root directory of this project.

  • Start the server by running the following command: go run main.go

  • Open your favorite web browser and navigate to: http://localhost:8080

  • Enter your text, select a banner, and click submit! To stop the server, go back to your terminal and press Ctrl + C.

Implementation Details: Algorithm

The server operates using Go's standard net/http and html/template packages, following a standard request-response lifecycle. Here is the step-by-step logic of how the code works under the hood:

  • Initialization (Template Caching): Before the server even starts listening for traffic, the init() function parses the index.html file and stores it in memory. This prevents the server from having to read the file from the hard drive on every single page load, drastically improving performance.

  • Routing: The main() function registers two specific routes to Go's default multiplexer (ServeMux):

    • / routes to the homeHandler.
    • /process routes to the processHandler.
    • It then starts listening on port 8080.
  • Handling the Home Page (homeHandler):

    • Acts as a strict gatekeeper. If the URL path is anything other than exactly /, it immediately returns a 404 Not Found error.
    • If the path is correct, it executes the cached HTML template with an empty PageData struct, rendering the blank form for the user.
  • Processing the Art (processHandler):

    • Validation: First, it checks if the incoming request is a POST request. If a user tries to access /process via a standard GET request, it blocks them with a 405 Method Not Allowed error.
    • Data Extraction: It pulls the user's text (Ascii_input) and selected style (banners) from the submitted HTML form data.
    • Generation: It passes these two variables to the external generator.ArtGenerator() function, which calculates and returns the final ASCII art string.
    • Dynamic Rendering: Finally, it packages the generated ASCII art into the PageData struct and injects it back into the index.html template. The server then sends this freshly updated HTML back to the user's browser to be displayed.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages