diff --git a/.deb.yaml b/.deb.yaml index 5ecaecb..0cce34e 100755 --- a/.deb.yaml +++ b/.deb.yaml @@ -1,6 +1,6 @@ package: jasta source: jasta -version: 1:0.3.3 +version: 1:0.4.0 architecture: - amd64 - arm64 diff --git a/.gitignore b/.gitignore index fdf9dc9..7dee038 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,19 @@ -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# -# Binaries for programs and plugins +.tools/ +bin/ +vendor/ +build/ +.idea/ +.vscode/ +coverage.txt +coverage.out *.exe *.exe~ *.dll *.so *.dylib - -# Test binary, built with `go test -c` +*.db +*.db-journal +*.mmdb *.test - -# Output of the go coverage tool, specifically when used with LiteIDE *.out - -# Dependency directories (remove the comment below to include it) -# vendor/ -.vscode/ -.idea/ - -# Go workspace file -go.work -.tools/ -build/ +.env \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 8a69106..6f3bc45 100755 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,180 +1,87 @@ -# options for analysis running run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 5m - - # exit code when at least one issue was found, default is 1 + go: "1.22.5" + concurrency: 4 + timeout: 5m + tests: false issues-exit-code: 1 - - # include test files or not, default is true - tests: true - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - skip-files: - - easyjson + modules-download-mode: readonly issues: - # Independently from option 'exclude' we use default exclude patterns, - # it can be disabled by this option. To list all - # excluded by default patterns execute 'golangci-lint run --help'. - # Default value for this option is true. exclude-use-default: false - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - # Exclude some linters from running on tests files. - - path: _test\.go - linters: - - prealloc - - errcheck + max-issues-per-linter: 100 + max-same-issues: 4 + new: false + exclude-files: + - ".+_test.go" + exclude-dirs: + - "vendor$" -# output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number" - format: colored-line-number + formats: + - format: line-number + sort-results: true - # print lines of code with issue, default is true - print-issued-lines: true - - # print linter name in the end of issue text, default is true - print-linter-name: true - -# all available settings of specific linters linters-settings: govet: - # report about shadowed variables check-shadowing: true - enable: - # report mismatches between assembly files and Go declarations - - asmdecl - # check for useless assignments - - assign - # check for common mistakes using the sync/atomic package - - atomic - # check for non-64-bits-aligned arguments to sync/atomic functions - - atomicalign - # check for common mistakes involving boolean operators - - bools - # check that +build tags are well-formed and correctly located - - buildtag - # detect some violations of the cgo pointer passing rules - - cgocall - # check for unkeyed composite literals - - composites - # check for locks erroneously passed by value - - copylocks - # check for calls of reflect.DeepEqual on error values - - deepequalerrors - # report passing non-pointer or non-error values to errors.As - - errorsas - # find calls to a particular function - - findcall - # report assembly that clobbers the frame pointer before saving it - - framepointer - # check for mistakes using HTTP responses - - httpresponse - # detect impossible interface-to-interface type assertions - - ifaceassert - # check references to loop variables from within nested functions - - loopclosure - # check cancel func returned by context.WithCancel is called - - lostcancel - # check for useless comparisons between functions and nil - - nilfunc - # check for redundant or impossible nil comparisons - - nilness - # check consistency of Printf format strings and arguments - - printf - # check for comparing reflect.Value values with == or reflect.DeepEqual - - reflectvaluecompare - # check for possible unintended shadowing of variables - - shadow - # check for shifts that equal or exceed the width of the integer - - shift - # check for unbuffered channel of os.Signal - - sigchanyzer - # check the argument type of sort.Slice - - sortslice - # check signature of methods of well-known interfaces - - stdmethods - # check for string(int) conversions - - stringintconv - # check that struct field tags conform to reflect.StructTag.Get - - structtag - # report calls to (*testing.T).Fatal from goroutines started by a test. - - testinggoroutine - # check for common mistaken usages of tests and examples - - tests - # report passing non-pointer or non-interface values to unmarshal - - unmarshal - # check for unreachable code - - unreachable - # check for invalid conversions of uintptr to unsafe.Pointer - - unsafeptr - # check for unused results of calls to some functions - - unusedresult - # checks for unused writes - - unusedwrite - disable: - # find structs that would use less memory if their fields were sorted - - fieldalignment + enable: + - asmdecl + - assign + - atomic + - atomicalign + - bools + - buildtag + - cgocall + - composites + - copylocks + - deepequalerrors + - errorsas + - findcall + - framepointer + - httpresponse + - ifaceassert + - loopclosure + - lostcancel + - nilfunc + - nilness + - printf + - reflectvaluecompare + - shadow + - shift + - sigchanyzer + - sortslice + - stdmethods + - stringintconv + - structtag + - testinggoroutine + - tests + - unmarshal + - unreachable + - unsafeptr + - unusedresult + - unusedwrite + disable: + - fieldalignment gofmt: - # simplify code: gofmt with '-s' option, true by default simplify: true errcheck: - # report about not checking of errors in type assetions: 'a := b.(MyStruct)'; - # default is false: such cases aren't reported by default. check-type-assertions: true - # report about assignment of errors to blank identifier: 'num, _ := strconv.Atoi(numStr)'; - # default is false: such cases aren't reported by default. check-blank: true gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 15 + min-complexity: 30 misspell: - # Correct spellings using locale preferences for US or UK. - # Default is to use a neutral variety of English. - # Setting locale to US will correct the British spelling of 'colour' to 'color'. locale: US prealloc: - # XXX: we don't recommend using this linter before doing performance profiling. - # For most programs usage of prealloc will be a premature optimization. - # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. - # True by default. simple: true - range-loops: true # Report preallocation suggestions on range loops, true by default - for-loops: true # Report preallocation suggestions on for loops, false by default + range-loops: true + for-loops: true unparam: - # Inspect exported functions, default is false. Set to true if no external program/library imports your code. - # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find external interfaces. All text editor integrations - # with golangci-lint call it on a directory with the changed file. check-exported: false gci: - # Section configuration to compare against. - # Section names are case-insensitive and may contain parameters in (). - # The default order of sections is 'standard > default > custom > blank > dot', - # If 'custom-order' is 'true', it follows the order of 'sections' option. - # Default: ["standard", "default"] - #sections: - #- standard # Standard section: captures all standard packages. - #- default # Default section: contains all imports that could not be matched to another section type. - #- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled. - #- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled. - # Skip generated files. - # Default: true skip-generated: true - # Enable custom order of sections. - # If 'true', make the section order the same as the order of 'sections'. - # Default: false custom-order: false gosec: - # To select a subset of rules to run. - # Available rules: https://github.com/securego/gosec#available-rules - # Default: [] - means include all rules includes: - G101 # Look for hard coded credentials - G102 # Bind to all interfaces @@ -210,9 +117,6 @@ linters-settings: - G504 # Import blocklist: net/http/cgi - G505 # Import blocklist: crypto/sha1 - G601 # Implicit memory aliasing of items from a range statement - # To specify a set of rules to explicitly exclude. - # Available rules: https://github.com/securego/gosec#available-rules - # Default: [] excludes: - G101 # Look for hard coded credentials - G102 # Bind to all interfaces @@ -248,104 +152,39 @@ linters-settings: - G504 # Import blocklist: net/http/cgi - G505 # Import blocklist: crypto/sha1 - G601 # Implicit memory aliasing of items from a range statement - # Exclude generated files - # Default: false exclude-generated: true - # Filter out the issues with a lower severity than the given value. - # Valid options are: low, medium, high. - # Default: low severity: medium - # Filter out the issues with a lower confidence than the given value. - # Valid options are: low, medium, high. - # Default: low confidence: medium - # Concurrency value. - # Default: the number of logical CPUs usable by the current process. concurrency: 12 - # To specify the configuration of rules. config: - # Globals are applicable to all rules. global: - # If true, ignore #nosec in comments (and an alternative as well). - # Default: false nosec: true - # Add an alternative comment prefix to #nosec (both will work at the same time). - # Default: "" "#nosec": "#my-custom-nosec" - # Define whether nosec issues are counted as finding or not. - # Default: false show-ignored: true - # Audit mode enables addition checks that for normal code analysis might be too nosy. - # Default: false audit: true G101: - # Regexp pattern for variables and constants to find. - # Default: "(?i)passwd|pass|password|pwd|secret|token|pw|apiKey|bearer|cred" - pattern: "(?i)example" - # If true, complain about all cases (even with low entropy). - # Default: false + pattern: "(?i)passwd|pass|password|pwd|secret|token|pw|apiKey|bearer|cred" ignore_entropy: false - # Maximum allowed entropy of the string. - # Default: "80.0" entropy_threshold: "80.0" - # Maximum allowed value of entropy/string length. - # Is taken into account if entropy >= entropy_threshold/2. - # Default: "3.0" per_char_threshold: "3.0" - # Calculate entropy for first N chars of the string. - # Default: "16" truncate: "32" - # Additional functions to ignore while checking unhandled errors. - # Following functions always ignored: - # bytes.Buffer: - # - Write - # - WriteByte - # - WriteRune - # - WriteString - # fmt: - # - Print - # - Printf - # - Println - # - Fprint - # - Fprintf - # - Fprintln - # strings.Builder: - # - Write - # - WriteByte - # - WriteRune - # - WriteString - # io.PipeWriter: - # - CloseWithError - # hash.Hash: - # - Write - # os: - # - Unsetenv - # Default: {} G104: fmt: - Fscanf G111: - # Regexp pattern to find potential directory traversal. - # Default: "http\\.Dir\\(\"\\/\"\\)|http\\.Dir\\('\\/'\\)" - pattern: "custom\\.Dir\\(\\)" - # Maximum allowed permissions mode for os.Mkdir and os.MkdirAll - # Default: "0750" + pattern: "http\\.Dir\\(\"\\/\"\\)|http\\.Dir\\('\\/'\\)" G301: "0750" - # Maximum allowed permissions mode for os.OpenFile and os.Chmod - # Default: "0600" G302: "0600" - # Maximum allowed permissions mode for os.WriteFile and ioutil.WriteFile - # Default: "0600" G306: "0600" lll: - # Max line length, lines longer will be reported. - # '\t' is counted as 1 character by default, and can be changed with the tab-width option. - # Default: 120. - line-length: 120 - # Tab width in spaces. - # Default: 1 + line-length: 130 tab-width: 1 + staticcheck: + go: "1.15" + # SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks + # Default: ["*"] + checks: [ "*", "-SA1019" ] linters: disable-all: true @@ -362,7 +201,6 @@ linters: - unused - prealloc - durationcheck - - nolintlint - staticcheck - makezero - nilerr @@ -371,5 +209,5 @@ linters: - exportloopref - gci - gosec - - lll +# - lll fast: false diff --git a/.lic.yaml b/.lic.yaml index c06bd92..2d88cc6 100755 --- a/.lic.yaml +++ b/.lic.yaml @@ -1,3 +1,3 @@ -author: Mikhail Knyazhev +author: Mikhail Knyazhev lic_short: BSD-3-Clause lic_file: LICENSE diff --git a/Makefile b/Makefile index 3ad9475..628ffe3 100755 --- a/Makefile +++ b/Makefile @@ -1,33 +1,30 @@ .PHONY: install install: - go install github.com/osspkg/devtool@latest - -.PHONY: setup -setup: - devtool setup-lib + go install go.osspkg.com/goppy/v2/cmd/goppy@latest + goppy setup-lib .PHONY: lint lint: - devtool lint + goppy lint .PHONY: license license: - devtool license + goppy license .PHONY: build build: - devtool build --arch=amd64 + goppy build --arch=amd64 .PHONY: tests tests: - devtool test + goppy test -.PHONY: pre-commite -pre-commite: setup lint build tests +.PHONY: pre-commit +pre-commit: lint build tests .PHONY: ci -ci: install setup lint build tests +ci: install pre-commit run_local: go run cmd/jasta/main.go --config=config/config.dev.yaml @@ -35,7 +32,7 @@ run_local: prerender_local: go run cmd/jasta/main.go prerender -deb: +deb: build deb-builder build local: build diff --git a/cmd/jasta/main.go b/cmd/jasta/main.go index 36ce5d7..9f799c8 100644 --- a/cmd/jasta/main.go +++ b/cmd/jasta/main.go @@ -1,26 +1,23 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ package main import ( - "github.com/osspkg/jasta/internal/command" - "github.com/osspkg/jasta/internal/jasta" - "go.osspkg.com/goppy" - "go.osspkg.com/goppy/web" + "go.arwos.org/jasta/internal/command" + "go.arwos.org/jasta/internal/jasta" + "go.osspkg.com/goppy/v2" + "go.osspkg.com/goppy/v2/web" ) var Version = "v0.0.0-dev" func main() { - app := goppy.New() - app.AppName("jasta") - app.AppDescription("Gateway for static sites") - app.AppVersion(Version) + app := goppy.New("jasta", Version, "Gateway for static sites") app.Plugins( - web.WithHTTP(), + web.WithServer(), ) app.Plugins( jasta.Plugins..., diff --git a/config/config.dev.yaml b/config/config.dev.yaml index e03a6b9..f344f10 100755 --- a/config/config.dev.yaml +++ b/config/config.dev.yaml @@ -1,11 +1,12 @@ env: dev + log: - level: 4 file_path: /dev/stdout format: string + level: 4 http: - main: - addr: 127.0.0.1:8080 + - addr: 0.0.0.0:8080 + tag: main websites: test_data diff --git a/config/config.yaml b/config/config.yaml index f29153f..94f1050 100755 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,11 +1,12 @@ -env: dev +env: prod + log: - level: 4 file_path: /var/log/jasta.log format: string + level: 4 http: - main: - addr: 127.0.0.1:15432 + - addr: 127.0.0.1:15432 + tag: main -websites: /etc/jasta/websites +websites: /etc/jasta/websites \ No newline at end of file diff --git a/go.mod b/go.mod index 336c700..45c015b 100644 --- a/go.mod +++ b/go.mod @@ -1,29 +1,29 @@ -module github.com/osspkg/jasta +module go.arwos.org/jasta -go 1.20 +go 1.22.5 require ( - go.osspkg.com/goppy v0.17.3 - go.osspkg.com/goppy/console v0.3.1 - go.osspkg.com/goppy/iofile v0.3.1 - go.osspkg.com/goppy/plugins v0.3.1 - go.osspkg.com/goppy/shell v0.3.0 - go.osspkg.com/goppy/syscall v0.3.0 - go.osspkg.com/goppy/web v0.3.2 - go.osspkg.com/goppy/xlog v0.3.1 + go.osspkg.com/console v0.3.3 + go.osspkg.com/do v0.1.2 + go.osspkg.com/events v0.3.0 + go.osspkg.com/goppy/v2 v2.1.5 + go.osspkg.com/ioutils v0.4.7 + go.osspkg.com/logx v0.4.2 go.osspkg.com/static v1.4.0 ) require ( github.com/josharian/intern v1.0.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect - go.osspkg.com/algorithms v1.3.1 // indirect - go.osspkg.com/goppy/app v0.3.3 // indirect - go.osspkg.com/goppy/env v0.3.0 // indirect - go.osspkg.com/goppy/errors v0.3.0 // indirect - go.osspkg.com/goppy/iosync v0.3.0 // indirect - go.osspkg.com/goppy/ioutil v0.3.0 // indirect - go.osspkg.com/goppy/xc v0.3.0 // indirect - go.osspkg.com/goppy/xnet v0.3.0 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect + go.osspkg.com/algorithms v1.4.1 // indirect + go.osspkg.com/config v0.1.3 // indirect + go.osspkg.com/errors v0.3.1 // indirect + go.osspkg.com/grape v1.2.3 // indirect + go.osspkg.com/network v0.4.5 // indirect + go.osspkg.com/syncing v0.3.0 // indirect + go.osspkg.com/xc v0.3.1 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 39969fa..7762572 100644 --- a/go.sum +++ b/go.sum @@ -1,49 +1,57 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -go.osspkg.com/algorithms v1.3.1 h1:Weh0Z4dMzHFRJTfMva/mU6Uk95wSRGwt1Saj2sfz3Wc= -go.osspkg.com/algorithms v1.3.1/go.mod h1:kj+oVK7UDQlXMKleMTYzbEEpUAXC2tzRBtki7F5EbXc= -go.osspkg.com/goppy v0.17.3 h1:ouLV9o2TTciR2+nkVzl9JPpm9HJMiNFlHPaWCDr3waM= -go.osspkg.com/goppy v0.17.3/go.mod h1:+lHoulh1Q0EU1LeWqnBfFyX+yvFsqQ5MsBnGHWTd4qE= -go.osspkg.com/goppy/app v0.3.3 h1:pQy1ptCg+8dloUx1icHtmJ9CEm4ZLgkiXlOfxMVLtlQ= -go.osspkg.com/goppy/app v0.3.3/go.mod h1:hv+T2GuR5hnDUI57qUsQQaN0wzg6I4FiuOcziEyoBG0= -go.osspkg.com/goppy/console v0.3.1 h1:fg1HDeev01h55k29B6LyzCDf3b2sn5yl3YYOGN2f4w0= -go.osspkg.com/goppy/console v0.3.1/go.mod h1:TpDVGqmJaKuxemUUPj/cNyLEo3jlyL/T0iOzsZDmjjY= -go.osspkg.com/goppy/env v0.3.0 h1:F4hq5KCjMfhXIcsNvbfQzdVHpB8ZVu7XMj0F1hZrq7c= -go.osspkg.com/goppy/env v0.3.0/go.mod h1:7r+0+1h2mFfat5vaWHPu4+Zl9vq6+raz59ScmqLe4zI= -go.osspkg.com/goppy/errors v0.3.0 h1:n98V9gW8UOfooY9Y9FNwV7oznKGQxrIr/J19brqayzc= -go.osspkg.com/goppy/errors v0.3.0/go.mod h1:rbBTNHK0wpGi3FgJ4M27n7LOvB3Aw6kKc0Q4np16wh0= -go.osspkg.com/goppy/iofile v0.3.1 h1:AwuU7PuCPfFAPRKZv2dlOoqrlQfE8T7lERFktbT6650= -go.osspkg.com/goppy/iofile v0.3.1/go.mod h1:2Efhu11htfc4/IIuWtJ8iIQB86kkBaDKslsaive8Kfs= -go.osspkg.com/goppy/iosync v0.3.0 h1:eClduMtjVZUPpNYzHm7EClCa3y58lB/FlIRtHgyU9YE= -go.osspkg.com/goppy/iosync v0.3.0/go.mod h1:Ocol//DRF4n0m40jFmYBxnjHtFjeyeO0RcY/pwOCtsg= -go.osspkg.com/goppy/ioutil v0.3.0 h1:dcjuZMrL2CXOMA9UbVlxMZvHXiRbwxFCMfh9hCPsdE4= -go.osspkg.com/goppy/ioutil v0.3.0/go.mod h1:pbyQ/pa301T+0T9rb9bZd6q4ofC4yVAFWu0sQvjitmc= -go.osspkg.com/goppy/plugins v0.3.1 h1:mxjcgs24BvCii19aKYCXVz+EpmW2qjT4JX6bsc8RgJk= -go.osspkg.com/goppy/plugins v0.3.1/go.mod h1:WTSeS/6B2K1FAciQBqHgE0u0t8BD94ehD+HK1hV/IrA= -go.osspkg.com/goppy/shell v0.3.0 h1:h1w3vRoaro2d6s/A1Tvghq5de8wHDwoobNONwhkxiJc= -go.osspkg.com/goppy/shell v0.3.0/go.mod h1:ZgAoKBOyHor1xyPZdgljNLh/gnd1EKiOhYhgFT3xueQ= -go.osspkg.com/goppy/syscall v0.3.0 h1:2PcpkqC1ol14HTOC+XyG+3lsuQ9pnG9ueE4xFywoSdE= -go.osspkg.com/goppy/syscall v0.3.0/go.mod h1:Vz1BCzM8MmyC/26SjiVh6OGcAkky1y4xalSWbVceiL4= -go.osspkg.com/goppy/web v0.3.2 h1:+U3JNcRHzbgrL0kOWFzCXL5YjZVmvL1tN8q8dQ0fL6E= -go.osspkg.com/goppy/web v0.3.2/go.mod h1:zrWR2jWXhF7TllfBVwXmCsk6u7qXHuIhqaIAXcJvV1k= -go.osspkg.com/goppy/xc v0.3.0 h1:3r10skiV63AO5OnjvbpEpLF8p8eqYB+AbRa6cnxKsmQ= -go.osspkg.com/goppy/xc v0.3.0/go.mod h1:Diqc/s597erdipSXBHSg5RZsFizleLrqxBCSwGeuktQ= -go.osspkg.com/goppy/xlog v0.3.1 h1:ZPzjau9cNiXbh7YbopRGWnEKhNndpNAEqwqPeqqHwrg= -go.osspkg.com/goppy/xlog v0.3.1/go.mod h1:YnsETZ6KaMKy8UA4u03rwRcsdJFMy1Jygsv5DYHHnLU= -go.osspkg.com/goppy/xnet v0.3.0 h1:rGzTtjGnRmk2s1ujI6Si6fXAS85WO2qeoQeoxfw34QI= -go.osspkg.com/goppy/xnet v0.3.0/go.mod h1:/XIH64sw58nOA3Ma7z6i26Kp8bqKMNQpdjAoI6FVe9Q= -go.osspkg.com/goppy/xtest v0.3.0 h1:QV0159LiYXKALfsOwhCG+zUuy5jnIFeopYs00PSRa2g= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +go.osspkg.com/algorithms v1.4.1 h1:yCXiNHu+MGiUYU7wFsCg2Q0drLPnu1q13cIrPAHDlXU= +go.osspkg.com/algorithms v1.4.1/go.mod h1:JarWCfCmgxBkk2tA/ABeHScK9WN8azu+bEc27+dF/Gw= +go.osspkg.com/casecheck v0.3.0 h1:x15blEszElbrHrEH5H02JIIhGIg/lGZzIt1kQlD3pwM= +go.osspkg.com/casecheck v0.3.0/go.mod h1:TRFXDMFJEOtnlp3ET2Hix3osbxwPWhvaiT/HfD3+gBA= +go.osspkg.com/config v0.1.3 h1:LAgTTYFzoIf4VNBIpFtjG81rR0/3SG29r+1D8I/YBzs= +go.osspkg.com/config v0.1.3/go.mod h1:MyqvXDgpHLZlO2SM/rqf1zogpUZiXvkZlc/Z+0L7alA= +go.osspkg.com/console v0.3.3 h1:UB/pPoPsgWbyNFix8pEMQHbsXdMv/UK/dgsbRknCH2A= +go.osspkg.com/console v0.3.3/go.mod h1:IknBCliH6mX/ogHa6wbycnGDFYixCGH3WuNc5W5tQe8= +go.osspkg.com/do v0.1.2 h1:e7J/R+vMTpF1NL2wF301rBu72DQ1dlhd/IXtjWYFreQ= +go.osspkg.com/do v0.1.2/go.mod h1:hOQEum85f8Kc4m8PWUAECDQ/mTtQ4362ABLD+KW5/vk= +go.osspkg.com/errors v0.3.1 h1:F9m/EEd/Ot2jba/TV7tvVRIpWXzIpNLc7vRJKcBD86A= +go.osspkg.com/errors v0.3.1/go.mod h1:dKXe6Rt07nzY7OyKQNZ8HGBicZ2uQ5TKEoVFnVFOK44= +go.osspkg.com/events v0.3.0 h1:W2IngTsKs0BKYIglqhrETwtpo6uNSZXWRIt0/l7c6dY= +go.osspkg.com/events v0.3.0/go.mod h1:Cjpx+qNM1y2MIAygFyZWYagTuRiYirmKppZQdaZumd4= +go.osspkg.com/goppy/v2 v2.1.5 h1:kW12lqxdyjx2u1TLPVqnOrIZo3rRHJ4kcDFzZU10iok= +go.osspkg.com/goppy/v2 v2.1.5/go.mod h1:7VDQjqkD1bBUyl6kkJCcfG/5Flk/EuVS7qZaB05FpJA= +go.osspkg.com/grape v1.2.3 h1:3umuC4AV8foY4rGz3xoUdtJ7iG8STTLjqSNZyDygc/o= +go.osspkg.com/grape v1.2.3/go.mod h1:lg0K0VqCQE1/o4c2xM4b/wL5ZKG2NkqqCCF16ZjEJSI= +go.osspkg.com/ioutils v0.4.7 h1:ERr37BhApkVH34Ebq2yPY+50p38bElSns6pX64wVsyw= +go.osspkg.com/ioutils v0.4.7/go.mod h1:58HhG2NHf9JUtixAH3R2XISlUmJruwVIUZ3039QVjOY= +go.osspkg.com/logx v0.4.2 h1:3kqG7EaaT/DxpHytQm4MfcrmDhYf8ha9/iRpVjpRt88= +go.osspkg.com/logx v0.4.2/go.mod h1:mGbH9hdkeC0h9Gw1uWgQfi9MmlANcqNLffB0wxIDpsQ= +go.osspkg.com/network v0.4.5 h1:1vNL62jIY6TF2wLxb2tEM7bDuCy2him5mk4WKj6+wnQ= +go.osspkg.com/network v0.4.5/go.mod h1:OKBbbdb/+Y7U6lArKjFEc0+drK45sKfc3IZ+B7ZfVO8= go.osspkg.com/static v1.4.0 h1:2uy4/11c0QP+QLMucKQZbAU+e6lhVHKw5dWJPTk/DBg= go.osspkg.com/static v1.4.0/go.mod h1:94YydVU3qUtb1J534486lpm+qg6CviQjqtxKlkpSppM= +go.osspkg.com/syncing v0.3.0 h1:yBkCsDPEt12a+qagInFFt7+ZongfT+GjSQl7nBmcybI= +go.osspkg.com/syncing v0.3.0/go.mod h1:Dpe0ljlEG6cI2Y9PxEjKiYEX2sgs1eUjWNVjFu4/iB0= +go.osspkg.com/xc v0.3.1 h1:6De75eXdP9CVXqgQOcCWLPyAqFw9zP5lM6rV9MLGiCE= +go.osspkg.com/xc v0.3.1/go.mod h1:6dUG4Y/Q2NMhc5vYrNy0ehWIaHQtAi+MFfc22onQHEs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/init/jasta.service b/init/jasta.service index 1bdf5c2..1750161 100755 --- a/init/jasta.service +++ b/init/jasta.service @@ -2,8 +2,8 @@ After=network.target [Service] -User=root -Group=root +User=www-data +Group=www-data Restart=on-failure RestartSec=30s Type=simple diff --git a/internal/command/nginx_config.go b/internal/command/nginx_config.go index 4011ffb..5d6260b 100644 --- a/internal/command/nginx_config.go +++ b/internal/command/nginx_config.go @@ -1,13 +1,14 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ package command import ( - "fmt" "os" + + "go.osspkg.com/console" ) const nginxConfigTemplate = ` @@ -28,10 +29,6 @@ server { func InstallNginxConfig() { err := os.WriteFile("/etc/nginx/sites-available/default", []byte(nginxConfigTemplate), 0744) - if err != nil { - fmt.Println(err.Error()) - os.Exit(1) - } - fmt.Println("Done") - os.Exit(0) + console.FatalIfErr(err, "write nginx config") + console.Infof("Done") } diff --git a/internal/command/prerender.go b/internal/command/prerender.go index 298319e..3c3cbf5 100644 --- a/internal/command/prerender.go +++ b/internal/command/prerender.go @@ -1,13 +1,13 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ package command import ( - "github.com/osspkg/jasta/internal/spiderweb" - "go.osspkg.com/goppy/console" + "go.arwos.org/jasta/internal/spiderweb" + "go.osspkg.com/console" ) func PreRenderStaticWebsites() { diff --git a/internal/jasta/config.go b/internal/jasta/config.go index 043ec1f..ba96854 100644 --- a/internal/jasta/config.go +++ b/internal/jasta/config.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ @@ -8,7 +8,7 @@ package jasta import ( "fmt" - "go.osspkg.com/goppy/iofile" + "go.osspkg.com/ioutils/fs" ) type Config struct { @@ -25,7 +25,7 @@ func (c *Config) Validate() error { if len(c.Websites) == 0 { return fmt.Errorf("websites folder path is not defined") } - if !iofile.Exist(c.Websites) { + if !fs.FileExist(c.Websites) { return fmt.Errorf("websites folder path is not exist") } return nil @@ -50,7 +50,7 @@ func (c *WebsiteConfig) Validate() error { if len(c.Domains) == 0 { return fmt.Errorf("invalid domain") } - if len(c.Root) == 0 || !iofile.Exist(c.Root) { + if len(c.Root) == 0 || !fs.FileExist(c.Root) { return fmt.Errorf("invalid root folder") } if len(c.AssetsFolder) == 0 { diff --git a/internal/jasta/jasta.go b/internal/jasta/jasta.go index ce51b54..3851ca0 100644 --- a/internal/jasta/jasta.go +++ b/internal/jasta/jasta.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ @@ -12,13 +12,14 @@ import ( "path/filepath" "strings" - "go.osspkg.com/goppy/web" - "go.osspkg.com/goppy/xlog" + "go.osspkg.com/do" + "go.osspkg.com/goppy/v2/web" + "go.osspkg.com/logx" "go.osspkg.com/static" ) const ( - extHTML = ".html" + mimeHTML = "text/html" ) type ( @@ -55,7 +56,7 @@ func (v *Jasta) Down() error { func (v *Jasta) handler(ctx web.Context) { ctx.Response().Header().Set("server", "jasta") - path := pathProtect(ctx.URL().Path) + path := protect(ctx.URL().Path) host, _, err := net.SplitHostPort(ctx.URL().Host) if err != nil { host = ctx.URL().Host @@ -63,44 +64,38 @@ func (v *Jasta) handler(ctx web.Context) { conf, ok := v.settings[host] if !ok { - ctx.Response().WriteHeader(403) - xlog.WithFields(xlog.Fields{ - "host": host, - }).Warnf("Host not found") + ctx.Response().WriteHeader(523) + logx.Warn("Host not found", "host", host) return } ext := filepath.Ext(path) if strings.HasPrefix(path, conf.Assets) && len(ext) > 0 { - doResponse(ctx.Response(), conf.Root, path, "", ext) + doResponse(ctx.Response(), conf.Root, path, "") return } if conf.Single { if len(ext) == 0 { - path = "index.html" + path = "/index.html" } - doResponse(ctx.Response(), conf.Root, path, "", ".html") } else { if len(ext) == 0 { path = strings.TrimRight(path, "/") + "/index.html" } - doResponse(ctx.Response(), conf.Root, path, conf.Page404, ".html") } + doResponse(ctx.Response(), conf.Root, path, conf.Page404) } func prepareSettings(c []*WebsiteConfig) map[string]Setting { result := make(map[string]Setting, 10) for _, item := range c { for _, domain := range item.Domains { - xlog.WithFields(xlog.Fields{ - "domain": domain, - "root": item.Root, - }).Infof("Load config") + logx.Info("Load config", "domain", domain, "root", item.Root) result[domain] = Setting{ Root: item.Root, Assets: item.AssetsFolder, - Page404: item.Page404, + Page404: do.IfElse(len(item.Page404) > 0 && item.Page404[0] == '/', item.Page404, "/"+item.Page404), Single: item.Single, } } @@ -109,30 +104,56 @@ func prepareSettings(c []*WebsiteConfig) map[string]Setting { return result } -func pathProtect(path string) string { - return strings.ReplaceAll(path, "../", "/") +func protect(path string) string { + i, j, n := 0, -1, len(path) + in, out := []byte(path), make([]byte, 0, n) + + for i < n { + switch true { + case (i == 0 || i+1 >= n) && in[i] == '.': + i++ + case in[i] == '.' && i+1 < n && (in[i+1] == '/' || in[i+1] == '.'): + i++ + case in[i] == '/' && i+1 < n && in[i+1] == '/': + i++ + case in[i] == '/' && i+1 < n && in[i+1] == '.': + if j >= 0 && out[j] != '/' { + out = append(out, in[i]) + j++ + } + i += 2 + default: + out = append(out, in[i]) + j++ + i++ + } + } + + return string(out) } -func doResponse(w http.ResponseWriter, root string, page string, page404 string, ext string) { - b, err := os.ReadFile(root + "/" + page) - code := 200 +func doResponse(w http.ResponseWriter, root string, p200 string, p404 string) { + b, err := os.ReadFile(root + do.IfElse(len(p200) > 0 && p200[0] == '/', "", "/") + p200) + code := do.IfElse(p200 == p404, 404, 200) if err != nil { - if len(page404) == 0 { + if len(p404) == 0 { w.WriteHeader(404) return } - if b, err = os.ReadFile(root + "/" + page404); err != nil { + b, err = os.ReadFile(root + do.IfElse(len(p404) > 0 && p404[0] == '/', "", "/") + p404) + if err != nil { w.WriteHeader(404) return } - code = 404 - page = page404 + code, p200 = 404, p404 } - - w.Header().Set("Content-Type", static.DetectContentType(page, b)) - if ext != extHTML { + mime := static.DetectContentType(p200, b) + w.Header().Set("Content-Type", mime) + if mime != mimeHTML { w.Header().Set("Cache-Control", "max-age=10800") } w.WriteHeader(code) - w.Write(b) //nolint: errcheck + if _, err = w.Write(b); err != nil { + logx.Error("Write response", "err", err, "page", p200) + } } diff --git a/internal/jasta/jasta_test.go b/internal/jasta/jasta_test.go new file mode 100644 index 0000000..fe3cc27 --- /dev/null +++ b/internal/jasta/jasta_test.go @@ -0,0 +1,64 @@ +package jasta + +import ( + "testing" +) + +func TestUnit_protect(t *testing.T) { + tests := []struct { + name string + path string + want string + }{ + { + name: "Case1", + path: "./..//....///index.html.", + want: "/index.html", + }, + { + name: "Case2", + path: "./..//....///index.html./", + want: "/index.html/", + }, + { + name: "Case3", + path: "./..//....///index.html.///", + want: "/index.html/", + }, + { + name: "Case4", + path: "./..//....///index.html.///.png/", + want: "/index.html/png/", + }, + { + name: "Case5", + path: "..../..//....///index.html.///.png/...", + want: "/index.html/png/", + }, + { + name: "Case6", + path: "/hello/asd.aaa/index.html", + want: "/hello/asd.aaa/index.html", + }, + { + name: "Case7", + path: "hello/asd.aaa/index.html", + want: "hello/asd.aaa/index.html", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := protect(tt.path); got != tt.want { + t.Errorf("protect() = %v, want %v", got, tt.want) + } + }) + } +} + +func BenchmarkProtect(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + protect("..../..//....///index.html.///.png/...") + } +} diff --git a/internal/jasta/plugin.go b/internal/jasta/plugin.go index bbc575b..5837b21 100644 --- a/internal/jasta/plugin.go +++ b/internal/jasta/plugin.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ @@ -7,10 +7,12 @@ package jasta import ( "fmt" + "path/filepath" + "strings" - "github.com/osspkg/jasta/internal/utils" - "go.osspkg.com/goppy/iofile" - "go.osspkg.com/goppy/plugins" + "go.osspkg.com/goppy/v2/plugins" + "go.osspkg.com/ioutils/codec" + "go.osspkg.com/ioutils/fs" ) var Plugins = plugins.Inject( @@ -25,7 +27,7 @@ var Plugins = plugins.Inject( func WebsiteConfigDecode(c *Config) (WebsiteConfigs, error) { result := make([]*WebsiteConfig, 0, 10) - files, err := utils.AllFileByExt(c.Websites, ".yaml") + files, err := fs.SearchFilesByExt(c.Websites, ".yaml") if err != nil { return nil, fmt.Errorf("detect websites configs: %w", err) } @@ -34,9 +36,16 @@ func WebsiteConfigDecode(c *Config) (WebsiteConfigs, error) { } for _, filename := range files { wc := &WebsiteConfig{} - if err = iofile.FileCodec(filename).Decode(wc); err != nil { + if err = codec.FileEncoder(filename).Decode(wc); err != nil { return nil, fmt.Errorf("invalid website config [%s]: %w", filename, err) } + if len(wc.Root) > 0 && wc.Root[0] == '.' { + filenameFull, err0 := filepath.Abs(filename) + if err0 != nil { + return nil, fmt.Errorf("validate root path for [%s]: %w", filename, err0) + } + wc.Root = filepath.Dir(filenameFull) + "/" + strings.TrimLeft(wc.Root, "./") + } if err = wc.Validate(); err != nil { return nil, err } diff --git a/internal/jasta/setup/version.go b/internal/jasta/setup/version.go new file mode 100644 index 0000000..6a1d0a2 --- /dev/null +++ b/internal/jasta/setup/version.go @@ -0,0 +1,5 @@ +package setup + +type Base struct { + Version string `yaml:"version"` +} diff --git a/internal/spiderweb/chromium.go b/internal/spiderweb/chromium.go index e41d21c..f36ab9b 100644 --- a/internal/spiderweb/chromium.go +++ b/internal/spiderweb/chromium.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ diff --git a/internal/spiderweb/config.go b/internal/spiderweb/config.go index 57b147d..f240600 100644 --- a/internal/spiderweb/config.go +++ b/internal/spiderweb/config.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ diff --git a/internal/spiderweb/spider.go b/internal/spiderweb/spider.go index 497c970..d881c60 100644 --- a/internal/spiderweb/spider.go +++ b/internal/spiderweb/spider.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. + * Copyright (c) 2023-2024 Mikhail Knyazhev . All rights reserved. * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. */ @@ -15,22 +15,20 @@ import ( "strings" "time" - "github.com/osspkg/jasta/internal/utils" - "go.osspkg.com/goppy/iofile" - "go.osspkg.com/goppy/shell" - "go.osspkg.com/goppy/syscall" + "go.osspkg.com/do" + "go.osspkg.com/events" + "go.osspkg.com/ioutils/codec" + "go.osspkg.com/ioutils/fs" + "go.osspkg.com/ioutils/shell" ) type Spider struct { - shell shell.Shell - tempDir string - config *Config + shell shell.TShell + config *Config } func New() *Spider { - return &Spider{ - tempDir: os.TempDir(), - } + return &Spider{} } func (v *Spider) Run() error { @@ -41,7 +39,7 @@ func (v *Spider) Run() error { return err } ctx, cncl := context.WithCancel(context.Background()) - go syscall.OnStop(cncl) + go events.OnStopSignal(cncl) all, err := v.grab(ctx) if err != nil { return err @@ -51,9 +49,7 @@ func (v *Spider) Run() error { func (v *Spider) initShell() error { v.shell = shell.New() - v.shell.SetShell("/bin/bash") - v.shell.SetDir(v.tempDir) - return nil + return v.shell.SetShell("/bin/bash", "x", "e", "c") } func (v *Spider) initConfig() error { @@ -62,11 +58,11 @@ func (v *Spider) initConfig() error { return err } filename := fmt.Sprintf("%s/%s", dir, configName) - if !iofile.Exist(filename) { + if !fs.FileExist(filename) { return fmt.Errorf("config not found in: %s", dir) } conf := &Config{} - if err = iofile.FileCodec(filename).Decode(conf); err != nil { + if err = codec.FileEncoder(filename).Decode(conf); err != nil { return err } v.config = conf @@ -87,7 +83,7 @@ func (v *Spider) grab(ctx context.Context) ([]string, error) { for _, uri := range urls { select { case <-ctx.Done(): - return utils.Map2Slice(all), nil + return do.Keys[string, struct{}](all), nil default: b, err := v.getHtml(ctx, uri) @@ -111,21 +107,26 @@ func (v *Spider) grab(ctx context.Context) ([]string, error) { continue } temp = append(temp, u.Path) - fmt.Println(u.Path) all[u.Path] = struct{}{} } } } } if len(temp) == 0 { - return utils.Map2Slice(all), nil + return do.Keys[string, struct{}](all), nil } urls = append(urls[:0], temp...) } } func (v *Spider) getHtml(ctx context.Context, uri string) ([]byte, error) { - b, err := v.shell.Call(ctx, fmt.Sprintf(runChromium, v.tempDir, v.config.DevHost+"/"+strings.TrimLeft(uri, "/"))) + tmpDir, err := os.MkdirTemp(os.TempDir(), "jasta-prerend-*") + if err != nil { + return nil, err + } + defer os.RemoveAll(tmpDir) // nolint: errcheck + v.shell.SetDir(tmpDir) + b, err := v.shell.Call(ctx, fmt.Sprintf(runChromium, tmpDir, v.config.DevHost+"/"+strings.TrimLeft(uri, "/"))) if err != nil { return nil, err } diff --git a/internal/utils/files.go b/internal/utils/files.go deleted file mode 100644 index 4a4d283..0000000 --- a/internal/utils/files.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. - * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. - */ - -package utils - -import ( - "io/fs" - "path/filepath" -) - -func AllFileByExt(dir, ext string) ([]string, error) { - files := make([]string, 0) - err := filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error { - if err != nil { - return err - } - if info.IsDir() || filepath.Ext(info.Name()) != ext { - return nil - } - files = append(files, path) - return nil - }) - return files, err -} diff --git a/internal/utils/map2slice.go b/internal/utils/map2slice.go deleted file mode 100644 index bc5eae0..0000000 --- a/internal/utils/map2slice.go +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2023 Mikhail Knyazhev . All rights reserved. - * Use of this source code is governed by a BSD-3-Clause license that can be found in the LICENSE file. - */ - -package utils - -import "sort" - -func Map2Slice(v map[string]struct{}) []string { - data := make([]string, 0, len(v)) - for s := range v { - data = append(data, s) - } - sort.Strings(data) - return data -} diff --git a/test_data/404.html b/test_data/multipage/404.html similarity index 100% rename from test_data/404.html rename to test_data/multipage/404.html diff --git a/test_data/index.html b/test_data/multipage/index.html similarity index 90% rename from test_data/index.html rename to test_data/multipage/index.html index 222897b..3f5686c 100644 --- a/test_data/index.html +++ b/test_data/multipage/index.html @@ -5,6 +5,6 @@ - Page Index + Multi Page diff --git a/test_data/localhost.yaml b/test_data/multipage/localhost.yaml similarity index 83% rename from test_data/localhost.yaml rename to test_data/multipage/localhost.yaml index 4ee8a63..41e8b88 100644 --- a/test_data/localhost.yaml +++ b/test_data/multipage/localhost.yaml @@ -1,6 +1,6 @@ domains: - localhost -root: test_data +root: ./ page404: 404.html assets_folder: /assets/ single: false diff --git a/test_data/robots.txt b/test_data/multipage/robots.txt similarity index 100% rename from test_data/robots.txt rename to test_data/multipage/robots.txt diff --git a/test_data/singlepage/404.html b/test_data/singlepage/404.html new file mode 100644 index 0000000..c97861a --- /dev/null +++ b/test_data/singlepage/404.html @@ -0,0 +1,9 @@ + + + + 404 + + + Page 404 + + diff --git a/test_data/singlepage/index.html b/test_data/singlepage/index.html new file mode 100644 index 0000000..7449bbb --- /dev/null +++ b/test_data/singlepage/index.html @@ -0,0 +1,10 @@ + + + + Index + + + + Single Page + + diff --git a/test_data/singlepage/localhost.yaml b/test_data/singlepage/localhost.yaml new file mode 100644 index 0000000..0761c5f --- /dev/null +++ b/test_data/singlepage/localhost.yaml @@ -0,0 +1,6 @@ +domains: + - 127.0.0.1 +root: ./ +page404: 404.html +assets_folder: /assets/ +single: true diff --git a/test_data/singlepage/robots.txt b/test_data/singlepage/robots.txt new file mode 100644 index 0000000..0d0298e --- /dev/null +++ b/test_data/singlepage/robots.txt @@ -0,0 +1 @@ +# ROBOTS \ No newline at end of file