zoukankan      html  css  js  c++  java
  • Go Web服务器和图片

    Web 服务器

    包 http 通过任何实现了 http.Handler 的值来响应 HTTP 请求:

    package http
    
    type Handler interface {
        ServeHTTP(w ResponseWriter, r *Request)
    }

    在这个例子中,类型 Hello 实现了 `http.Handler`。

    访问 http://localhost:4000/ 会看到来自程序的问候。

    注意: 这个例子无法在基于 web 的指南用户界面运行。为了尝试编写 web 服务器,可能需要安装 Go

    package main
    
    import (
    	"fmt"
    	"net/http"
    )
    
    type Hello struct{}
    
    func (h Hello) ServeHTTP(
    	w http.ResponseWriter,
    	r *http.Request) {
    	fmt.Fprint(w, "Hello!")
    }
    
    func main() {
    	var h Hello
    	http.ListenAndServe("localhost:4000", h)
    }
    

    图片

    Package image 定义了 Image 接口:

    package image
    
    type Image interface {
        ColorModel() color.Model
        Bounds() Rectangle
        At(x, y int) color.Color
    }

    (参阅文档了解全部信息。)

    同样,`color.Color` 和 color.Model 也是接口,但是通常因为直接使用预定义的实现image.RGBA 和 image.RGBAModel 而被忽视了。这些接口和类型由image/color 包定义。

    package main
    
    import (
    	"fmt"
    	"image"
    )
    
    func main() {
    	m := image.NewRGBA(image.Rect(0, 0, 100, 100))
    	fmt.Println(m.Bounds())
    	fmt.Println(m.At(0, 0).RGBA())
    }
    
  • 相关阅读:
    eclipse中的项目如何打成war包
    【SVN】Please execute the 'Cleanup' command.
    2021.06.02模拟赛DP2
    2021.05.26模拟赛 DP1
    状压DP
    高斯消元
    矩阵快速幂
    2021.05.10讲题
    Luogu P2152[SDOI 2009]Super GCD
    Tarjan
  • 原文地址:https://www.cnblogs.com/liyuzhao/p/3887847.html
Copyright © 2011-2022 走看看