-1

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.

dupree
  • 1
  • 1
  • use http://golang.org/pkg/os/#Getwd and print the value (log.Println) returned. Can we safely assume you are not using `go run` as well? – elithrar Jul 26 '14 at 23:29
  • Yes I am using `go run main.go` command to start/deploy the .go files. – dupree Jul 27 '14 at 07:33

1 Answers1

0

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).

Elwinar
  • 9,103
  • 32
  • 40
  • Hi,I tried again by moving my public/ folder to $GOPATH\bin folder but the same problem persists. My $GOPATH variable is set to C:\Users\usrname\go_projects\go – dupree Jul 26 '14 at 21:11
  • Did you try to access `http://localhost:3000` or `http://localhost:3000/index.html` ? I don't think that martini handle auto-indexing… – Elwinar Jul 26 '14 at 23:25