Not able to access static webpage index.html via martini framework

282 Views Asked by At

Hi I am trying to access and display a static index.html page via martini framework. But I am always getting 404 not found error. The .html file is in public/index.html where the /public directory is in my go/src/github.com/user/ directory. I am able to display Hello World!! via martini through code -

    package main

    // loading in the Martini package
    import "github.com/codegangsta/martini"

    func main() {
      // if you are new to Go the := is a short variable declaration
      m := martini.Classic()

      // the func() call is creating an anonymous function that retuns a stringa
      m.Get("/", func() string {
        return "Hello World !!"
      })

      m.Run()

}

So I am sure that martini is configured quiet correctly. But when I try to access a static webpage via -

package main

import (
        "github.com/codegangsta/martini"
        //"log"
        //"net/http"

)

func main() {
        m := martini.Classic()
        m.Run()
}

I just get 404 on localhot:3000. Any help how can I access the html file?

PS - I am trying to do something similar mentioned here- https://gophercasts.io/lessons/3-martini-and-markdown

Edit - using m.Use(martini.Static("C:/Users/shrinr/go_projects/go/bin/public")) does not help either, where my $GOPATH is C:/Users/shrinr/go_projects/go.

1

There are 1 best solutions below

2
On

Assuming that you are compiling your program using the standard procedure of Go (in the $GOPATH), the problem is that your binary isn't in the same directory than your public/ folder. You should put it in the $GOPATH/bin folder (where should lie your binary).