Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:50:25+00:00 2026-06-14T04:50:25+00:00

I wrote a very basic web application, following this tutorial. I want to add

  • 0

I wrote a very basic web application, following this tutorial. I want to add css rules in an external stylesheet, but it’s not working – when the HTML templates are rendered, something goes wrong and the CSS is completely ignored. If I put the rules in tags, it works, but I don’t want to have to deal with that.

In a Go web application, how do I render an external CSS stylesheet?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:50:26+00:00Added an answer on June 14, 2026 at 4:50 am

    Add a handler to handle serving static files from a specified directory.

    eg. create {server.go directory}/resources/ and use

    http.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources")))) 
    

    along with /resources/somethingsomething.css

    The reason for using StripPrefix is that you can change the served directory as you please, but keep the reference in HTML the same.

    eg. to serve from /home/www/

    http.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("/home/www/"))))
    

    Note that this will leave the resources directory listing open.
    If you want to prevent that, there is a good snippet on the go snippet blog:

    http://gosnip.posterous.com/disable-directory-listing-with-httpfileserver

    Edit: Posterous is now gone, so I just pulled the code off of the golang mailing list and will post it here.

    type justFilesFilesystem struct {
        fs http.FileSystem
    }
    
    func (fs justFilesFilesystem) Open(name string) (http.File, error) {
        f, err := fs.fs.Open(name)
        if err != nil {
            return nil, err
        }
        return neuteredReaddirFile{f}, nil
    }
    
    type neuteredReaddirFile struct {
        http.File
    }
    
    func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
        return nil, nil
    }
    

    Original post discussing it: https://groups.google.com/forum/#!topic/golang-nuts/bStLPdIVM6w

    And use it like this in place of the line above:

     fs := justFilesFilesystem{http.Dir("resources/")}
     http.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(fs)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK. this might be a very basic question to please don't flame me but
I wrote a very basic program but was not able to understand the behaviour
I'm attempting to write a very basic script using javascript. What I want to
I'm trying to write a very basic macro in VB for Microsoft Word, but
I wrote this very simple macro to delete all rows when Column P has
I'm VERY new to Linq. I have an application I wrote that is in
i am developing a very basic prototype of web search engine and now i
Ok guys, this is very basic stuff I think. I'm only getting familiar with
This is a very basic question. I'm just on my mission to learn ASP.NET
I want to use twisted.web templates together twisted.web resources. But I just don't get,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.