S
S
Sergey Ilyin2022-01-12 01:12:05
go
Sergey Ilyin, 2022-01-12 01:12:05

What is the error in the code when routing to go?

there is a simple Go code (2 pages with a transition between them):

package main

import (
  "fmt"
  "net/http"

  "github.com/julienschmidt/httprouter"
)

func index_page(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
  http.ServeFile(w, r, "index.html")
}

func login_page(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
  fmt.Fprintf(w, "тест")
}

func handleRequest() {
    router := httprouter.New()
    router.GET("/", index_page)
    router.GET("/login", login_page)
    http.Handle("/", router)
    http.ListenAndServe(":8000", router)
}

func main() {
  handleRequest()
}


html index:

<html>
    <head>
        <title>login or auth?</title>
    </head>
    <body>
        <h2>Стартовая страничка</h2>

            <a href = "login_page.html">
                <input class="button" value="Войти"/>
            </a>
            <a href = "reg_page.html">
                <input class="button" value="Регистрация"/>
            </a>
    </body>
</html>


I compile, run - the index page opens, when you try to go - it crashes with a 404 error.

Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
montray, 2022-01-12
@quiex

Read about url, uri and it would also be desirable to study the protocol with which you are working.

S
Sergey Ilyin, 2022-01-12
@sunsexsurf

so. the first stage of solving the problem turned out to be that we need to fix html, namely href: change to
<a href = "login_page.html">
<a href = "/login">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question