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
67ac824a
authored
Dec 25, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
ee221d82
1b1acd6b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
2 deletions
code/application.go
code/webloghandler.go
main.go
mainbak.go
code/application.go
0 → 100644
View file @
67ac824a
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 @
67ac824a
...
...
@@ -67,7 +67,7 @@ func (wbh *WebHandler) indexhandle(w http.ResponseWriter, r *http.Request) {
func
(
wbh
*
WebHandler
)
Indexhandle2
(
ctx
iris
.
Context
)
{
innerip
:=
ctx
.
URLParam
(
"innerip"
)
server_direc
:=
ctx
.
URLParam
(
"server_direc"
)
file
:=
ctx
.
URLParam
(
"file"
)
file
:=
ctx
.
URLParam
(
"file
name
"
)
if
innerip
!=
""
{
ip_files
,
err
:=
get_files
(
wbh
.
Directory
+
"/"
+
innerip
)
...
...
main.go
View file @
67ac824a
package
main
import
(
"github.com/kataras/iris/v12"
"os"
"web_log/code"
)
...
...
@@ -16,6 +17,7 @@ func main() {
if
logenv
==
"PRODUCT"
{
Directory
=
"/data/soft/rsync_log"
}
code
.
See
(
Directory
,
TestPort
)
app
:=
code
.
GetApp
(
Directory
,
TestPort
)
app
.
Run
(
iris
.
Addr
(
"0.0.0.0:9997"
),
iris
.
WithCharset
(
"UTF-8"
))
}
mainbak.go
0 → 100644
View file @
67ac824a
package
main
import
(
"os"
"web_log/code"
)
// example
func
main
()
{
Directory
:=
"E:
\\
test_logs"
// directory of the log
TestPort
:=
9997
logenv
:=
os
.
Getenv
(
"GOLOGENV"
)
if
logenv
==
"TEST"
{
Directory
=
"/data/soft/bigdatav3.0/test_rsync_log"
}
if
logenv
==
"PRODUCT"
{
Directory
=
"/data/soft/rsync_log"
}
code
.
See
(
Directory
,
TestPort
)
}
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