Delivering HTML content using GoLang

Trying to display an HTML page using a golang API.

Below is the HTML content:

<!DOCTYPE HTML>
<html>
    
    <body>
      <section>
      <div class="login-box">
    <h2>Login into your account</h2>
    <form method="post" action="/login">
        <label for="name"></label>
        <input type="text" placeholder="Username" id="name" name="name"><br>
        <label for="password"></label>
        <input  type="password" placeholder="Password" id="password" name="password"> <br>
        <br>
        <button type="submit">Login</button>
    </form>
       
        </div>
      <br>
    <nav class="myNav">
        <ul>
            <li><a href="">Don't have an account?</a>
              <ul>
                <li><a href="">Sing Up</a></li>
                <li><a href="">Login with Google Account</a></li>
              </ul>
          </li>
        </ul>
      </nav>
      </section>
     </html>
<style>
  .login-box{
    font-size: large;
    position:absolute;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
  }
  .login-box input{
    border:none;
    outline:none;
    font-size:20px;
    text-align: center;
  }
  
button{
  width:30%;
  position:absolute;
  left:70%;
  background:none;
  border: 2px solid white;
  padding: 4px;
  cursor:pointer;
  font-size: 18px;
  font-family: "Lucida Console", Courier, monospace;
}

label{
  color:black;
  font-family: 'Comfortaa';
  font-size:30px;
}
body {

  width:100%;
  height:100vh;
    background: linear-gradient(-45deg, #23D5AB, #23A6D5,#E73C7E);
    background-size:300% 300%; 
    position:relative;
    animation:change 10s ease-in-out infinite;
}
  @keyframes change{
    0%{
      background-position: 0 50%;
    }
    50%{
      background-position: 100% 50%;
    }
    100%{
      background-position: 0 50%;
    }
  }
.myNav ul {
  margin:0;
  padding:0;
  list-style: none;

}
.myNav >ul {
  display:flex;
  flex-direction:column;

}
ul a{
    display: block;
    padding: .5rem;
    background: #262626;
    color: #fff;
    font-size: 20px;
    text-decoration: none;
  }

 .myNav a:hover,
 .myNav a:focus 
  {
    background:crimson;
  }
 .myNav >ul ul a{
    padding-left: 3rem;
    /*flex-direction: column;*/
  }
@media (min-width: 500px){
  .myNav ul{
    flex-direction:row;
  }

  .myNav >ul ul{
    position:relative;
    display:none;
    transition: .4s ease opacity;
    /*display:none;*/
    
  }
  .myNav >ul>li:hover ul,
  .myNav >ul>li:focus-within ul{
    display:block; 
    position:absolute;
  }
 
  .myNav > li {
    position: relative;
   flex:1; 
  }
  .myNav >ul>li:hover ul,
  .myNav >ul>li:focus-within ul{
    display:block; 
  }

}
  h2{
      font-family: 'Comfortaa';
      font-size:45px;
      border-bottom: 2px solid #fff;
      
  }
</style>

    </body>
       
 </html>        

The serving of this html is done through Go API using: router.HandleFunc("/", Utilities.LoginPage)

Rendering the HTML natively or on codepen shows expected results, but when served via the Go API, the appearance is not the same!

Appreciate any assistance. Thank you!

Answer №1

When it comes to hosting static files, one option is utilizing the net/http File Server in Golang. By creating a directory within your project repository and setting up a handler with the http.FileServer method, you can easily serve static files. Here's an example:

Let's say we have saved our file as index.html under the directory tmp

package main

import (
    "net/http"
)

func main() {
    http.Handle("/", http.FileServer(http.Dir("./tmp")))
    http.ListenAndServe(":8080", nil)
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am experiencing an issue where the HTTPS images are not appearing on my localhost, but when I click on the

While browsing a website, my browser is authenticated for the current session. I am utilizing their API to retrieve images from the site and displaying them on my webpage. Interestingly, directly visiting the image's URL displays the image without a ...

Ensure the navbar remains visible by avoiding the need to include "bg-dark" class

As I work on creating a website using Laravel and Bootstrap, I encountered an issue with the navbar element. Originally set to navbar-light, I modified it to navbar-dark in order to achieve a dark and transparent navbar. Additionally, I removed the class b ...

The Materialize CSS tabs are aligning vertically below each other, but functioning correctly upon refreshing the page

When using materialize css tabs, all the divs load one below the other on the initial page load. If I refresh the page, it starts behaving properly. <div class="row"> <div class="col s12"> <ul class="tabs"> <li class="tab col s ...

How to use jQuery to display only the following div with a matching class

I'm encountering an issue while attempting to perform a series of steps using jQuery. Unfortunately, I am unable to achieve the desired outcome. There are 3 steps, each with a class of .wiki-step- followed by a number. Here is my JavaScript code: fu ...

Automatic refreshing of page at specified intervals

My website allows users to add posts and comments, similar to social media platforms. While everything is working smoothly, I am facing an issue with the auto-update feature. I would like the page to automatically refresh every 20 seconds to display any n ...

Make sure to have the list available while choosing an item

I want to design a unique CSS element with the following characteristics: Include a button. When the button is clicked, a list of items (like a dropdown list) should appear. We should be able to select items by clicking on them, and the parent component s ...

Duplicating the HTML code while in Firefox's "No Style" browsing mode

There are certain webpages that become more user-friendly when the "No Style" option is selected in Firefox (View > Page Style > No Style): for example, the text adapts more quickly. Is it feasible to save websites in the exact format they appear wi ...

Finding the perfect pairing: How to align counters with objects?

public counter = 0; x0: any; x1: any; x2: any; x3: any; x4: any; next(){ this.counter += 1; this.storage.set("Count", this.counter); console.log(this.counter); this.logic(); } logic(){ //automatic counter here var xNum = JSON.parse(JSON.stri ...

What is the best sequence for loading angularjs, bootstrap, sp js libraries, and jquery?

I have a unique single application that requires the use of bootstrap, ui bootstrap, angularjs, and jquery. The functionality of the button below is working correctly, but I am experiencing issues with the styling. You can check out a sample of alerts here ...

Adjusting the gaps between each item in a list

Currently, I am working on developing a minimalist single-page website. However, I am facing challenges with spacing in the navbar section (as demonstrated below). When using an unordered list, everything looks good until the list overlaps with the centra ...

Creating a dynamic table with LaravelCollective in Laravel 6: A step-by-step guide

I'm struggling to create a dynamic table using LaravelCollective, where users can add or remove rows. Despite following tutorials, I have been unsuccessful in getting it to work. I'm not sure what I'm doing wrong. HTML Code for the Table/F ...

Tips for ensuring a row and its columns take up the full height of their parent element (jumbotron)

https://i.sstatic.net/1LtQ8.jpg I need assistance with aligning the slogan vertically and horizontally within the jumbotron. The top logo is positioned correctly, but I want the small icon to be at the bottom of the jumbotron. Any help would be greatly a ...

Stacking SVG elements can lead to distortion effects

Currently experimenting with the innovative SVG stacking method to integrate multiple icons into a single file, reducing the browser's HTTP requests. The details of this technique can be found in depth here. In essence, it involves placing numerous S ...

Is it possible to utilize an integrated web browser (like Chrome) as the graphical user interface toolkit for Java desktop applications?

Wow, those HTML5 websites really stand out - but why is it that my Java desktop apps just don't have the same visual appeal? Swing and SWT seem outdated in comparison. They get the job done, but creating modern GUIs with animations and other flashy fe ...

The execution of JQuery/Javascript is restricted to only the initial condition within a Visualforce page utilizing the apex:outputpanel tag

After using only JavaScript for some time, I decided to try out jQuery. However, I'm facing an issue with executing a jQuery function. It seems that only the first condition in my code (the first IF) is being executed, while the second one (the second ...

Angular framework does not trigger the button click event

Currently, I am in the process of creating a web app and working on designing the register page. My experience with Angular is still at a beginner level. The following code snippet is from the resiger.component.ts file: /** * To create a new User ...

JavaScript: Storing text in arrays and managing multiple textareas

Is there a way to load a parent page into an object tag if the code doesn't seem to be appearing in the <object>? Here's what I've tried: var page = parent.document.documentElement.innerHTML; alert(page); document.getEleme ...

Plugin for creating a navigation bar with a jQuery and Outlook-inspired style

Our team is considering transitioning our asp.net forms application to MVC. Currently, we utilize outlook-style navigation with ASP controls such as listview and accordion, using code referenced here. Are there any jQuery/CSS controls available for MVC t ...

Issue with the position of the search dropdown in HTML

When we click on the Dropdown option, it appears above the text instead of below. I have been trying to fix the positioning issue where the Dropdown shows up separately after clicking, but I have not been successful so far. Maybe you can offer some assist ...

Vue component lacking Scss styling

One of the components in my project is an Img component, which includes a figure with a nested image element: <figure> <img @dragstart="stopDrag" :src="src" /> </figure> When using this component within another comp ...