Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix project layout #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Mac OS X files
.DS_Store

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# Dependency directories (remove the comment below to include it)
# vendor/
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM golang:1.12.8 AS builder
ENV SERVICE_NAME=rancher-catalog-stats
WORKDIR /go/src/github.com/rancherlabs/rancher-catalog-stats/
ADD src .
ADD . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ${SERVICE_NAME} .

FROM alpine:3.15.4
Expand All @@ -25,12 +25,15 @@ ENV SERVICE_NAME=rancher-catalog-stats \
ENV PATH=${PATH}:${SERVICE_HOME}

WORKDIR $SERVICE_HOME

COPY --from=builder /go/src/github.com/rancherlabs/rancher-catalog-stats/${SERVICE_NAME} ${SERVICE_HOME}
COPY --from=builder /go/src/github.com/rancherlabs/rancher-catalog-stats/GeoLite2-City.mmdb.gz ${SERVICE_HOME}

RUN gzip -d GeoLite2-City.mmdb.gz && \
rm -rf GeoLite2-City.mmdb.gz && \
addgroup -g ${SERVICE_GID} ${SERVICE_GROUP} && \
adduser -g "${SERVICE_NAME} user" -D -h ${SERVICE_HOME} -G ${SERVICE_GROUP} -s /sbin/nologin -u ${SERVICE_UID} ${SERVICE_USER} && \
chown -R ${SERVICE_USER}:${SERVICE_GROUP} ${SERVICE_HOME}

USER $SERVICE_USER

File renamed without changes.
2 changes: 1 addition & 1 deletion src/go.mod → go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/rancherlabs/rancher-catalog-stats/src
module github.com/rancherlabs/rancher-catalog-stats

go 1.12

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 23 additions & 18 deletions src/request.go → request.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,39 @@ func (r *Request) getData(str string, geoipdb string) error {

r.Ip = cli_ip
r.Host = submatches[2]
r.parseTimestamp(submatches[1])

err = r.parseTimestamp(submatches[1])

if err != nil {
log.Error("Could not parse timestamp")
}

r.getLocation(geoipdb)

if logFormatVersion == "2" {
r.Status = submatches[7]
r.Referer = submatches[9]
r.Agent = submatches[10]
r.Uid = submatches[13]
r.parseRequest(submatches[6])

err := r.parseRequest(submatches[6])

if err != nil {
log.Error("Could not parse request")
}
}

if logFormatVersion == "1" {
r.Status = submatches[6]
r.Referer = submatches[8]
r.Agent = submatches[9]
r.Uid = submatches[12]
r.parseRequest(submatches[5])

err := r.parseRequest(submatches[5])

if err != nil {
log.Error("Could not parse request")
}
}

return nil
Expand Down Expand Up @@ -288,14 +304,6 @@ func (c *ChannelList) Len() int {
return len(c.Readers)
}

// Initialize a new request from the input string
func NewRequest(str string, geoipdb string) (*Request, error) {
req := &Request{}

req.getData(str, geoipdb)
return req, nil
}

type Requests struct {
Exit chan os.Signal
Control *ChannelList
Expand Down Expand Up @@ -436,7 +444,10 @@ func (r *Requests) getDataByFile(f string) {
}
case line := <-t.Lines:
if line == nil {
t.Stop()
err = t.Stop()
if err != nil {
log.Error("Could not stop")
}
return
}
r.getData(string(line.Text), data)
Expand Down Expand Up @@ -543,12 +554,6 @@ func (r *Requests) getDataByFiles() {
}
}

func (r *Requests) getDataByLines(lines []string, data chan *Request) {
for _, line := range lines {
r.getData(string(line), data)
}
}

func (r *Requests) getData(line string, data chan *Request) {
req := &Request{}
err := req.getData(line, r.Config.geoipdb)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading