Go设计模式之代理模式讲解和代码示例

  package main

  import "fmt"

  func main() {

  nginxServer := newNginxServer()

  appStatusURL := "/app/status"

  createuserURL := "/create/user"

  httpCode, msg := nginxServer.handleRequest(appStatusURL, "GET")

  fmt.Printf("

  Url: %s

  HttpCode: %d

  Body: %s

  ", appStatusURL, httpCode, msg)

  httpCode, msg = nginxServer.handleRequest(appStatusURL, "GET")

  fmt.Printf("

  Url: %s

  HttpCode: %d

  Body: %s

  ", appStatusURL, httpCode, msg)

  httpCode, msg = nginxServer.handleRequest(appStatusURL, "GET")

  fmt.Printf("

  Url: %s

  HttpCode: %d

  Body: %s

  ", appStatusURL, httpCode, msg)

  httpCode, msg = nginxServer.handleRequest(createuserURL, "POST")

  fmt.Printf("

  Url: %s

  HttpCode: %d

  Body: %s

  ", appStatusURL, httpCode, msg)

  httpCode, msg = nginxServer.handleRequest(createuserURL, "GET")

  fmt.Printf("

  Url: %s

  HttpCode: %d

  Body: %s

  ", appStatusURL, httpCode, msg)

  }