skydive前端代码框架分析

skydive前端代码:
https://github.com/skydive-project/skydive/tree/master/statics

前端代码使用框架分析:
以vue-2.1.9框架为主进行开发的。其它第三方插件为:bootstrap、d3、jquery.1.9.1、jquery-ui.1.10.1、lscache、popper、tooltip、v-tooltip。
项目中的功能js组件写在:statics/js/components下。

前端代码分析:
1.总体上来说是完全前后端分离的,该代码能跑起来。
2.但其要通过后端读取相关配置项目(skydive_service_ip:prot/api),具体有:

http://skydive_service_ip:prot/api/
http://skydive_service_ip:prot/api/config/ui.theme 
http://skydive_service_ip:prot/api/config/analyzer.ssh_enabled
http://skydive_service_ip:prot/api/config/ui.bandwidth_threshold
http://skydive_service_ip:prot/api/config/analyzer.capture_enabled
http://skydive_service_ip:prot/api/config/ui.bandwidth_update_rate
http://skydive_service_ip:prot/api/config/analyzer.packet_injection_enabled
http://skydive_service_ip:prot/api/config/ui.topology.favorites

因为存在跨域问题(No 'Access-Control-Allow-Origin' header is present on the requested resource.),前端无法请求到相关信息。
解决办法(猜想):
方法一:后端添加相关代码,可参考:https://studygolang.com/articles/6713。全局搜索后端代码:w.Header().Set("content-type",在其上方添加:

w.Header().Set("Access-Control-Allow-Origin", "*") 
w.Header().Add("Access-Control-Allow-Headers", "Content-Type")

然后重新编译放到相应的位置,这里要知道:
(1)代码、环境搭建、编译、运行,这四步是如何运行起来的?通过docker容器没有得到答案。
(2)analyzer端和agent端程序是根据那一部分代码编译出来,还是都是同一个编译好的文件?
根据官方的安装文档(https://skydive-project.github.io/skydive/getting-started/install/),是整个代码编译出来后,再分别启动analyzer端(skydive agent [--conf etc/skydive.yml])和agent端(skydive analyzer [--conf etc/skydive.yml])。在ubuntu中搭建,没有运行成功,原因:官方文档中提到的相关依赖没有正确安装好。

所以该解决办法还没验证是否可行。

方法二:因为该前端框架使用的是vue2,其中Vue-cli proxyTable 可解决开发环境的跨域问题(https://www.jianshu.com/p/95b2caf7e0da),但该办法只适合用于开发阶段。
3.该前端代码,在<head></head>中嵌入了一小段go的模版语言,用于引入对应的js文件。
引入的go模版语言如下 :

<!-- extra assets -->
<< range $i, $asset := .ExtraAssets >>
<< if eq $asset.Ext ".css" >>
<link rel="stylesheet" href="<< $asset.Filename >>" />
<< end >>
<< if eq $asset.Ext ".js" >>
<script src="<< $asset.Filename >>"></script>
<< end >>
<< end >>
</head>

基主界面中,该部分并没有这部分的相关代码,后期删掉该代码,估计影响也不大。

总结:
1.首先要完成从go源码==》环境搭建==》源码编译==》项目运行起来,走通这个步骤。再往下做,看可不可行。
2.熟悉vue前端框架,方便后期使用与参考该部分的前端代码。

猜你喜欢

转载自www.cnblogs.com/a963383404/p/8966653.html
今日推荐