LollipopGo:游戏资源服

设计目的

游戏客户端热更需要,主要是代码热更,本篇简单给大家建立夏资源服的设计思路

代码

package main

import (
    "encoding/json"
    "fmt"
    "github.com/golang/glog"
    "io/ioutil"
    "log"
    "net/http"
    "os"
)

// 注意:Test会自己创建
func main() {
    http.HandleFunc("/Test", binge)
    os.Mkdir("Test", 0777)
    http.Handle("/Test/", http.StripPrefix("/Test/", http.FileServer(http.Dir("Test"))))
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

// 更新地址
type UpdateST struct {
    URL    string
    Flag   bool
    Fir_IM string
}

func binge(w http.ResponseWriter, req *http.Request) {

    w.Header().Set("Access-Control-Allow-Origin", "*")
    w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
    w.Header().Set("Access-Control-Allow-Headers", "Action, Module")
    w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization")
    w.Header().Set("Access-Control-Max-Age", "1728000")
    w.Header().Set("Access-Control-Allow-Credentials", "true")
    w.Header().Add("Access-Control-Allow-Headers", "Content-Type")
    w.Header().Set("content-type", "application/json")
    req.ParseForm()

    defer func() {
        if err := recover(); err != nil {
            glog.Info("%s", err)
            req.Body.Close()
        }
    }()
    s, _ := ioutil.ReadAll(req.Body)
    fmt.Println("------------------------------", string(s))
    glog.Info(string(s))
    glog.Flush()
    // 发送数据
    data := &UpdateST{
        URL:    "",
        Flag:   true,
        Fir_IM: "",
    }
    datamsgbak, _ := json.Marshal(data)
    fmt.Fprintf(w, "%s", datamsgbak)
    return
}

测试连接

// http://127.0.0.1:8080/Test/
注:Test为根目录文件夹,Test文件夹下面放热更文件。

你可能感兴趣的:(LollipopGo:游戏资源服)