package main
import "encoding/json"
import "fmt"
import "strconv"
import (
"github.com/drone/routes"
"net/http"
)
type ResInfo struct { //定义一个struct,然后这个struct里面有哪些子对象
Data YearDataStruct
Msg string
}
type YearDataStruct struct {
MouthAll []MouthStruct //定义一个类型为数组的对象,然后这个数组的元素类型为某种struct
Sum DetailStruct
Average DetailStruct
Quarter []QuarterStruct
}
type DetailStruct struct {
One int
Two int
Three int
}
type QuarterStruct struct {
DetailStruct //可以嵌套复合其他类型的struct,这样就继承下了其他struct的子对象
QuarterNum int
}
type MouthStruct struct {
Mouth int
PartmentItem []ItemArrStruct
}
type ItemArrStruct struct {
PartMent string
DetailStruct
}
func cross(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "*") //允许访问所有域
w.Header().Add("Access-Control-Allow-Headers", "Content-Type") //header的类型
w.Header().Set("content-type", "application/json") //返回数据格式是json
}
func main() {
fmt.Println("正在启动WEB服务...")
var mux *routes.RouteMux = routes.New()
mux.Get("/test", DataSend)
//http.Handle("/", mux)
http.ListenAndServe(":8088", mux)
fmt.Println("服务已停止")
}
func DataSend(w http.ResponseWriter, r *http.Request) {
var data YearDataStruct
for i := 1; i < 13; i++ {
var partMent []ItemArrStruct
for t := 1; t < 4; t++ {
partMent = append(partMent, ItemArrStruct{
PartMent: "" + strconv.Itoa(t) + "abc",
DetailStruct: DetailStruct{ //继承其他struct的子对象的赋值方法是这样的,one two 之类的和partment是同一等级
One: 45,
Two: 23,
Three: 3432,
},
})
}
data.MouthAll = append(data.MouthAll, MouthStruct{
Mouth: i,
PartmentItem: partMent,
})
}
for i := 1; i
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com