设为首页 加入收藏

TOP

Golang写https服务端
2017-09-30 13:53:45 】 浏览:5218
Tags:Golang https 服务

1. 生成私钥
openssl genrsa -out key.pem 2048
2. 生成证书
openssl req -new -x509 -key key.pem -out cert.pem -days 1095
3. 服务端代码:

package main

import (
"fmt"
"log"
"net/http"
)

func test(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "this is a test for you")
}

func main() {
http.HandleFunc("/test", test)
err := http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil)
if err != nil {
  log.Fatal("ListenerAndServe:", err)
}
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Cheatsheet: 2016 08.01 ~ 08.31 下一篇golang bytes.Buffer Reset

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目