LoginSignup
0
0

More than 5 years have passed since last update.

【Golang】 1つプロセスで複数のサイトを運営する方法【Echo】

Posted at

すごいことをタイトルで言ってるように見えるが、ただ単にリクエストのURLを見て処理を分けるだけ。

main.go
package main

import(
    "net/http"
    "github.com/labstack/echo"
)

func main() {
    e := echo.New()
    e.GET("/",root)
    e.Start(":8080")
}
func root(c echo.Context) error {
    if e.Request().Host == "localhost:8080"{
        return c.JSON(http.StatusOK,e.Request().Host)   
    }else{
        return c.JSON(http.StatusBadRequest,e.Request().Host)
    }
}
requset.sh
$curl localhost:8080
localhost:8080
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0