Skip to content

Commit aa211b5

Browse files
authored
Merge pull request #65 from webability-go/late-night
patch v1.5.5
2 parents 6aa82b7 + a7e62e8 commit aa211b5

8 files changed

Lines changed: 56 additions & 51 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,11 @@ The stat function is a public function from any of your loaded plugins.
461461
The general syntax is:
462462

463463
```
464-
import "github.com/webability-go/xamboo/cms/context"
464+
import "github.com/webability-go/xamboo/components/host"
465465
466-
func Log(ctx *context.Context) {
466+
func Log(hw *host.HostWriter) {
467467
// do the log
468+
// The RequestStat and the Context objects are into the HostWriter parameters
468469
}
469470
```
470471

@@ -1415,6 +1416,15 @@ Extras:
14151416

14161417
# Version Changes Control
14171418

1419+
v1.5.5 - 2021-03-08
1420+
-----------------------
1421+
- Change of logstat function definition, for log:stat:call:app:logstat it is now func(host.HostWriter).
1422+
- The stat component sets the RequestStat en the HostWriter params.
1423+
- The cms component sets the Context en the HostWriter params.
1424+
- The HostWriter should contain the requeststat and the context object in the parameters, if needed.
1425+
- The loggers Hook function is now an interface{} that should be a func(host.HostWriter) compatible function.
1426+
- Reference manual (this document) modified to meet the changes.
1427+
14181428
v1.5.4 - 2021-03-08
14191429
-----------------------
14201430
- deflate encoder implemented into compress component

applications/linker.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package applications
22

33
import (
4-
// "fmt"
54
"os"
65
"plugin"
76
"strings"
87
"sync"
98

109
"github.com/webability-go/xcore/v2"
1110

12-
"github.com/webability-go/xamboo/cms/context"
1311
"github.com/webability-go/xamboo/compiler"
12+
"github.com/webability-go/xamboo/components/host"
1413
"github.com/webability-go/xamboo/config"
1514
"github.com/webability-go/xamboo/loggers"
1615
"github.com/webability-go/xamboo/utils"
@@ -146,23 +145,23 @@ func LinkCalls() {
146145
xlogger := loggers.GetCoreLogger("sys")
147146
xlogger.Println("Build Applications External")
148147
xloggererror := loggers.GetCoreLogger("errors")
149-
for _, host := range config.Config.Hosts {
148+
for _, cfhost := range config.Config.Hosts {
150149

151-
if len(host.Log.Stats) > 6 {
152-
logdata := strings.Split(host.Log.Stats, ":")
150+
if len(cfhost.Log.Stats) > 6 {
151+
logdata := strings.Split(cfhost.Log.Stats, ":")
153152
if len(logdata) == 3 && logdata[0] == "call" {
154-
lib := GetApplicationPlugin(host.Name + "|" + logdata[1])
153+
lib := GetApplicationPlugin(cfhost.Name + "|" + logdata[1])
155154
if lib == nil {
156-
xloggererror.Println("Error, the host application to call in the stat log does not exists: " + host.Log.Stats)
155+
xloggererror.Println("Error, the host application to call in the stat log does not exists: " + cfhost.Log.Stats)
157156
continue
158157
}
159158
ihook, err := lib.Lookup(logdata[2])
160-
hook, ok := ihook.(func(*context.Context))
159+
hook, ok := ihook.(func(host.HostWriter))
161160
if err != nil || !ok {
162161
xloggererror.Println("Failed to find stat call function:", logdata[1], logdata[2], err)
163162
continue
164163
}
165-
loggers.SetHostHook(host.Name, "stats", hook)
164+
loggers.SetHostHook(cfhost.Name, "stats", hook)
166165
}
167166
}
168167
}

cms/cms.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/webability-go/xamboo/cms/engines/assets"
2222
"github.com/webability-go/xamboo/cms/identity"
2323
"github.com/webability-go/xamboo/components/host"
24-
"github.com/webability-go/xamboo/components/stat"
24+
// "github.com/webability-go/xamboo/components/stat"
2525
)
2626

2727
func Start() {
@@ -200,16 +200,7 @@ func (s *CMS) Run(page string, innerpage bool, params interface{}, version strin
200200
}
201201
// Assign the context to the statwriter parameters if it exists and is a correct RequestStat
202202
hw := s.writer.(host.HostWriter)
203-
p := hw.GetParams()
204-
if p != nil {
205-
ireq, _ := p.Get("RequestStat")
206-
if ireq != nil {
207-
req, ok := ireq.(*stat.RequestStat)
208-
if ok {
209-
req.Context = ctx
210-
}
211-
}
212-
}
203+
hw.SetParam("context", ctx)
213204

214205
// 1. Build-in engines
215206
var xdata string

components/log/log.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,44 @@ func (log *Log) Handler(handler http.HandlerFunc) http.HandlerFunc {
4747
http.Error(w, "C[log]: Writer error (see logs for more info)", http.StatusInternalServerError)
4848
return
4949
}
50-
host := hw.GetHost()
51-
if host == nil {
50+
hwhost := hw.GetHost()
51+
if hwhost == nil {
5252
slg.Println("C[log]: Critical error: there is no HOST in the host writer (and that should not happen)", r, w)
5353
http.Error(w, "C[log]: Writer error (see logs for more info)", http.StatusInternalServerError)
5454
return
5555
}
5656

57-
lg := loggers.GetHostLogger(host.Name, "sys")
58-
if host.Debug {
57+
lg := loggers.GetHostLogger(hwhost.Name, "sys")
58+
if hwhost.Debug {
5959
lg.Println("C[log]: We are going to serve the handler.")
6060
}
6161

6262
handler.ServeHTTP(w, r)
6363

64-
if host.Debug {
65-
lg.Println("C[log]: We have served the handler, log enabled:", host.Log.Enabled)
64+
if hwhost.Debug {
65+
lg.Println("C[log]: We have served the handler, log enabled:", hwhost.Log.Enabled)
6666
}
67-
if host.Log.Enabled {
67+
if hwhost.Log.Enabled {
6868
// Read the PARAMS
6969
// Read the loggers
7070
// Log the data
7171
p := hw.GetParams()
72-
ireq, _ := p.Get("RequestStat")
73-
req := ireq.(*stat.RequestStat)
74-
75-
hlogger := loggers.GetHostLogger(req.Hostname, "pages")
76-
if hlogger != nil {
77-
hlogger.Println(BuildLogLine(host.Log.PagesFormat, buildLogParams(hw)))
78-
}
79-
slogger := loggers.GetHostHook(req.Hostname, "stats")
80-
if slogger != nil && req.Context != nil {
81-
slogger(req.Context)
72+
ireq, _ := p.Get("requeststat")
73+
if ireq != nil {
74+
req, ok := ireq.(*stat.RequestStat)
75+
if ok {
76+
hlogger := loggers.GetHostLogger(req.Hostname, "pages")
77+
if hlogger != nil {
78+
hlogger.Println(BuildLogLine(hwhost.Log.PagesFormat, buildLogParams(hw)))
79+
}
80+
islogger := loggers.GetHostHook(req.Hostname, "stats")
81+
if islogger != nil {
82+
slogger, ok := islogger.(func(host.HostWriter))
83+
if ok {
84+
slogger(hw)
85+
}
86+
}
87+
}
8288
}
8389
}
8490
}
@@ -94,7 +100,10 @@ func buildLogParams(hw host.HostWriter) map[string]string {
94100
params := hw.GetParams()
95101

96102
for id, p := range params.Parameters {
97-
if id == "RequestStat" {
103+
if id == "context" {
104+
continue
105+
}
106+
if id == "requeststat" {
98107
if p.Value != nil {
99108
req, ok := p.Value.(*stat.RequestStat)
100109
if ok {

components/stat/request.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77

88
"github.com/webability-go/xamboo/config"
99
"github.com/webability-go/xamboo/loggers"
10-
11-
"github.com/webability-go/xamboo/cms/context"
10+
// "github.com/webability-go/xamboo/cms/context"
1211
)
1312

1413
/*
@@ -29,7 +28,6 @@ type RequestStat struct {
2928
IP string
3029
Port string
3130
Alive bool
32-
Context *context.Context `json:"-"`
3331
}
3432

3533
type SiteStat struct {

components/stat/stat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (st *Stat) Handler(handler http.HandlerFunc) http.HandlerFunc {
4949
req := CreateRequestStat(r.Host+r.URL.Path, r.Method, r.Proto, 0, 0, 0, r.RemoteAddr)
5050
req.Hostname = host.Name
5151
sw := writer{writer: hw, RequestStat: req}
52-
hw.SetParam("RequestStat", req)
52+
hw.SetParam("requeststat", req)
5353

5454
if host.Debug {
5555
lg.Println("C[stat]: statwriter created, we are going to serve the handler.")
@@ -64,6 +64,6 @@ func (st *Stat) Handler(handler http.HandlerFunc) http.HandlerFunc {
6464
req.UpdateStat(sw.status, sw.length)
6565
req.End()
6666
// Send the final stats data to the Params of hostwriter
67-
hw.SetParam("RequestStat", req)
67+
hw.SetParam("requeststat", req)
6868
}
6969
}

loggers/loggers.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package loggers
22

33
import (
4-
// "fmt"
54
"io"
65
"io/ioutil"
76
"log"
87
"os"
98
"strings"
109

11-
"github.com/webability-go/xamboo/cms/context"
1210
"github.com/webability-go/xamboo/config"
1311
)
1412

1513
type Logger struct {
1614
TypeOfLogger string
1715
File string
1816
Logger *log.Logger
19-
Hook func(*context.Context)
17+
Hook interface{}
2018
}
2119

2220
var Loggers = map[string]*Logger{}
@@ -129,11 +127,11 @@ func GetHostLogger(id string, cat string) *log.Logger {
129127
return Loggers["H["+id+"]["+cat+"]"].Logger
130128
}
131129

132-
func GetHostHook(id string, cat string) func(*context.Context) {
130+
func GetHostHook(id string, cat string) interface{} {
133131
return Loggers["H["+id+"]["+cat+"]"].Hook
134132
}
135133

136-
func SetHostHook(id string, cat string, h func(*context.Context)) {
134+
func SetHostHook(id string, cat string, h interface{}) {
137135
if Loggers["H["+id+"]["+cat+"]"] != nil {
138136
Loggers["H["+id+"]["+cat+"]"].Hook = h
139137
}

xamboo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
package xamboo
2727

2828
// VERSION last oficial published version of the xamboo on github.com
29-
const VERSION = "1.5.4"
29+
const VERSION = "1.5.5"

0 commit comments

Comments
 (0)