首页 技术 正文
技术 2022年11月10日
0 收藏 652 点赞 2,958 浏览 1496 个字
package mainimport (
"io/ioutil"
"log"
"net/http"
"os"
)var zpath string = "D:/Download/jQuery LigerUI V1.3.2/Source/" //LigerUI安装路径
var zport string = ""
var zsource_file = "source.config"
var zport_file = "port.config"
var staticHandler http.Handlerfunc Init() { if sourceExist(zport_file) {
log.Println("Port file is " + zport_file)
ztemp_port := filetostr(zport_file)
if ztemp_port != "" {
zport = ztemp_port
}
} else {
log.Println("Port file not exist ,please set server port in file " + zport_file)
log.Println("Server will use default port 80")
} if sourceExist(zsource_file) {
log.Println("Config file is " + zsource_file)
ztemp_path := filetostr(zsource_file)
if ztemp_path != "" {
zpath = ztemp_path
}
} else {
log.Println("Source file not exist ,please set LigerUI source path in file " + zsource_file)
log.Println("Server will use default LigerUI path")
}
staticHandler = http.FileServer(http.Dir(zpath))
}func indexPage(w http.ResponseWriter, req *http.Request) {
log.Println(req.URL.Path)
if req.URL.Path != "/" {
staticHandler.ServeHTTP(w, req)
return
}
//处理主页127.0.0.1
req.URL.Path = "/index.htm"
staticHandler.ServeHTTP(w, req)
}func main() {
Init() log.Println("LigerUI Source Path:")
log.Println(zpath) zport_str := ""
if zport != "" {
zport_str = ":" + zport
}
log.Println("Start LigerUI Server " + "127.0.0.1" + zport_str) http.HandleFunc("/", indexPage) err := http.ListenAndServe(":"+zport, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}}func sourceExist(filename string) bool {
_, err := os.Stat(filename)
return err == nil || os.IsExist(err)
}func filetostr(zfilename string) string {
zbyte, err := ioutil.ReadFile(zfilename)
zstr := ""
if err == nil {
zstr = string(zbyte) }
return zstr
}

golang为LigerUI编写简易版本web服务器

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,107
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,583
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,430
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,201
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919