Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
web_log
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
23ea8bab
authored
Dec 24, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
采用iris框架
parent
830d16ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
1 deletions
code/application.go
code/webloghandler.go
main.go → mainbak.go
code/application.go
0 → 100644
View file @
23ea8bab
package
code
import
(
"fmt"
"github.com/kataras/iris/v12"
"log"
"net/url"
"os"
"strings"
"time"
)
func
GetApp
(
directory
string
,
port
int
)
*
iris
.
Application
{
app
:=
iris
.
New
()
w
:=
&
WebHandler
{
"E:
\\
test_logs"
}
app
.
Get
(
"/index"
,
w
.
Indexhandle2
)
app
.
Get
(
"/ws"
,
genCtxHand
(
directory
,
manager
.
filemap
))
go
manager
.
start
()
return
app
}
func
genCtxHand
(
directory
string
,
file_map
map
[
string
]
map
[
Client
]
bool
)
func
(
ctx
iris
.
Context
)
{
f
:=
func
(
ctx
iris
.
Context
)
{
w
:=
ctx
.
ResponseWriter
()
r
:=
ctx
.
Request
()
// 完成ws协议的握手操作
// Upgrade:websocket
ws
,
err
:=
upGrader
.
Upgrade
(
w
,
r
,
nil
)
if
err
!=
nil
{
return
}
cli
:=
&
Client
{
time
.
Now
()
.
String
(),
ws
,
make
(
chan
[]
byte
,
1024
),
""
}
queryform
,
err
:=
url
.
ParseQuery
(
r
.
URL
.
RawQuery
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
filename
:=
queryform
[
"file"
][
0
]
//初始监听时加载最后500行全部内容
file_path
:=
directory
for
_
,
s
:=
range
strings
.
Split
(
filename
,
"~~"
)
{
file_path
+=
"/"
+
s
}
_
,
err
=
os
.
Stat
(
file_path
)
if
err
!=
nil
{
return
}
lastcontent_msg
,
err
:=
return_init_str
(
file_path
,
500
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
return
}
cli
.
Initstr
=
lastcontent_msg
// 监控文件
if
_
,
ok
:=
file_map
[
filename
];
ok
{
file_map
[
filename
][
*
cli
]
=
true
fmt
.
Printf
(
"%s has been monitored
\n
"
,
filename
)
}
else
{
go
monitor
(
file_path
,
filename
)
l
:=
make
(
map
[
Client
]
bool
)
l
[
*
cli
]
=
true
file_map
[
filename
]
=
l
fmt
.
Printf
(
"Add a new monitored file [%s]
\n
"
,
filename
)
}
//注册client并开始传输信息
manager
.
register
<-
cli
go
cli
.
read
()
cli
.
write
()
}
return
f
}
code/webloghandler.go
View file @
23ea8bab
...
@@ -67,7 +67,7 @@ func (wbh *WebHandler) indexhandle(w http.ResponseWriter, r *http.Request) {
...
@@ -67,7 +67,7 @@ func (wbh *WebHandler) indexhandle(w http.ResponseWriter, r *http.Request) {
func
(
wbh
*
WebHandler
)
Indexhandle2
(
ctx
iris
.
Context
)
{
func
(
wbh
*
WebHandler
)
Indexhandle2
(
ctx
iris
.
Context
)
{
innerip
:=
ctx
.
URLParam
(
"innerip"
)
innerip
:=
ctx
.
URLParam
(
"innerip"
)
server_direc
:=
ctx
.
URLParam
(
"server_direc"
)
server_direc
:=
ctx
.
URLParam
(
"server_direc"
)
file
:=
ctx
.
URLParam
(
"file"
)
file
:=
ctx
.
URLParam
(
"file
name
"
)
if
innerip
!=
""
{
if
innerip
!=
""
{
ip_files
,
err
:=
get_files
(
wbh
.
Directory
+
"/"
+
innerip
)
ip_files
,
err
:=
get_files
(
wbh
.
Directory
+
"/"
+
innerip
)
...
...
main.go
→
main
bak
.go
View file @
23ea8bab
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment