From 4e50fa04b33be5264588c7cd1cbd1bf59cb186bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E6=B5=B7=E4=BB=B2=E5=AD=90?= Date: Mon, 17 Oct 2022 22:45:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0description=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 24 ++++++++++++++++++++++++ .vscode/launch.json | 2 +- Dockerfile | 15 +++++++++++++++ docker-compose.debug.yml | 10 ++++++++++ docker-compose.yml | 10 ++++++++++ go.mod | 2 +- model/domain-model.go | 2 -- service/site-service.go | 12 +++++++----- 8 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.debug.yml create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..720e7a0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,24 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +README.md diff --git a/.vscode/launch.json b/.vscode/launch.json index b60f50f..e77f124 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "/Users/suguo/project/search" + "program": "/home/suguo/project/search" } ] } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a506713 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +#build stage +FROM golang:alpine AS builder +RUN apk add --no-cache git +WORKDIR /go/src/app +COPY . . +RUN go get -d -v ./... +RUN go build -o /go/bin/app -v ./... + +#final stage +FROM alpine:latest +RUN apk --no-cache add ca-certificates +COPY --from=builder /go/bin/app /app +ENTRYPOINT /app +LABEL Name=search Version=0.0.1 +EXPOSE 3000 diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml new file mode 100644 index 0000000..0932909 --- /dev/null +++ b/docker-compose.debug.yml @@ -0,0 +1,10 @@ +version: '3.4' + +services: + search: + image: search + build: + context: . + dockerfile: ./Dockerfile + ports: + - 3000:3000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0932909 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.4' + +services: + search: + image: search + build: + context: . + dockerfile: ./Dockerfile + ports: + - 3000:3000 diff --git a/go.mod b/go.mod index 72cbe3a..406c325 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module myschools.me/suguo/search go 1.19 require ( + github.com/PuerkitoBio/goquery v1.8.0 github.com/google/uuid v1.3.0 golang.org/x/net v0.0.0-20221014081412-f15817d10f9b gorm.io/driver/mysql v1.4.1 @@ -11,7 +12,6 @@ require ( ) require ( - github.com/PuerkitoBio/goquery v1.8.0 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect diff --git a/model/domain-model.go b/model/domain-model.go index 1e1b4a0..a1f0d16 100644 --- a/model/domain-model.go +++ b/model/domain-model.go @@ -6,6 +6,4 @@ type Domain struct { Root string `gorm:"type:varchar(10);primarykey"` CreatedAt time.Time UpdatedAt time.Time `gorm:"index"` - Success uint64 - Failure uint64 } diff --git a/service/site-service.go b/service/site-service.go index df916da..e558e83 100644 --- a/service/site-service.go +++ b/service/site-service.go @@ -41,12 +41,14 @@ func siteAccess(url *string) { } title := doc.Find("title").Text() - r, _ := doc.Find("head").Html() - fmt.Println(r) description := "" - if title != "" && description != "" { - //goto search - fmt.Println(title, description) + doc.Find("meta").Each(func(i int, s *goquery.Selection) { + if name, _ := s.Attr("name"); name == "description" { + description, _ = s.Attr("content") + } + }) + if title == "" || description == "" { + return } urls := urlAnalysis(resp.Body)