Initial commit of fibonacci_http_go

This commit is contained in:
Richard Robert Reitz 2024-12-16 11:49:51 +01:00
parent 6a88aeb484
commit d840abd759
23 changed files with 299 additions and 518 deletions

12
.gitignore vendored
View file

@ -1,12 +0,0 @@
# 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

View file

@ -1 +0,0 @@

View file

@ -1,10 +0,0 @@
language: go
go:
- 1.10.x
go_import_path: github.com/t-pwk/go-fibonacci
before_script:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
script:
- go test -v -covermode=count -coverprofile=coverage.out ./...
- "$HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN"

View file

@ -1,17 +1,17 @@
FROM golang:1.23.2 AS builder
WORKDIR /shared-data/app
WORKDIR /app
COPY ./ ./
# RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o fibonacci_go .
RUN CGO_ENABLED=0 GOOS=linux go build -o fibonacci-go cmd/main.go
# ToDo: use stretch as image for a completly empty container
FROM alpine:3.20.3
WORKDIR /shared-data/app
WORKDIR /app
COPY --from=builder /shared-data/app/fibonacci_go .
COPY --from=builder /app/fibonacci-go .
ENTRYPOINT [ "/shared-data/app/fibonacci_go" ]
ENTRYPOINT [ "/app/fibonacci-go" ]

21
LICENSE
View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018 Tom
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -19,9 +19,11 @@ Often, especially in modern usage, the sequence is extended by one more initial
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
```
This implementation has two methods: `Fibonacci` and `FibonacciBig`.
## Implementation Details
This implementation has three methods: `Fibonacci`, `FibonacciBig` and `FibonacciFromString`.
The `Fibonacci` function is more efficient, however, it returns correct numbers between 0 and 93 (inclusive). The `FibonacciBig` function, on the other hand, is less efficient but returns practically any Fibonacci number.
The `FibonacciFromString` function accepts the input number as a string and it can return an error if the input is not a positive number. This function is used, if the app is called from the HTTP-Server.
Example:
@ -45,3 +47,12 @@ And the output is
20: 6765
200: 280571172992510140037611932413038677189525
```
# HTTP-Server for access
A HTTP-Server is used to access the fibonacchi app remotely.
The HTTP-Server can be reached on port 9090 on the path '/fibonacchi' of the server domain.
If it is used on the domain https://cnoe.localtest.me, the fibonacchi value of 1000 can be calculated using the URL https://cnoe.localtest.me/fibonacci?number=1000. The app can calculate the fibonacchi number of values up to 5.000.000.
The calculated result is displayed on the HTML page.

View file

@ -1,78 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: ci-workflow-using-cluster-templates-
namespace: argo
labels:
workflows.argoproj.io/archive-strategy: "false"
annotations:
workflows.argoproj.io/description: |
This is a simple ci workflow that utilizes ClusterWorkflowTemplates.
spec:
entrypoint: ci
serviceAccountName: admin
volumeClaimTemplates:
- metadata:
name: shared-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
volumes:
- name: docker-config
secret:
secretName: my-docker-secret
templates:
- name: ci
dag:
tasks:
- name: git-clone
templateRef:
name: git-clone-template
template: git-clone
clusterScope: true
arguments:
parameters:
- name: git-repo
value: "https://forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/Franz.Germann/fibonacci_go.git"
- name: unit-tests
templateRef:
name: unit-tests-template
template: unit-tests
clusterScope: true
dependencies: [git-clone]
- name: lint-scan
templateRef:
name: lint-scan-template
template: lint-scan
clusterScope: true
dependencies: [git-clone]
- name: build
templateRef:
name: build-and-push-image-template
template: build
clusterScope: true
arguments:
parameters:
- name: dockerfile-name
value: "Dockerfile"
- name: image-destination
value: "gitea.cnoe.localtest.me/giteaadmin/fibonacci_go:latest"
dependencies: [unit-tests, lint-scan]
- name: trivy-filesystem-scan
templateRef:
name: trivy-filesystem-scan-template
template: trivy-filesystem-scan
clusterScope: true
dependencies: [git-clone]
- name: trivy-image-scan
templateRef:
name: trivy-image-scan-template
template: trivy-image-scan
clusterScope: true
arguments:
parameters:
- name: image
value: "gitea.cnoe.localtest.me/giteaadmin/fibonacci_go:latest"
dependencies: [build]

View file

@ -1,168 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: example-ci-workflow-
namespace: argo
labels:
workflows.argoproj.io/archive-strategy: "false"
annotations:
workflows.argoproj.io/description: |
This is a simple workflow to show what steps we need to take to deploy an application.
spec:
entrypoint: ci
serviceAccountName: admin
volumeClaimTemplates:
- metadata:
name: shared-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
volumes:
- name: docker-config
secret:
secretName: my-docker-secret
templates:
- name: ci
dag:
tasks:
- name: git-clone
template: git-clone
- name: ls
template: ls
dependencies: [git-clone]
- name: build
template: build
dependencies: [unit-tests, lint-scan]
- name: unit-tests
template: unit-tests
dependencies: [ls]
- name: lint-scan
template: lint-scan
dependencies: [ls]
- name: trivy-image-scan
template: trivy-image-scan
dependencies: [build]
- name: trivy-filesystem-scan
template: trivy-filesystem-scan
dependencies: [git-clone]
- name: deploy-image
template: simple-container
# when: " == true"
dependencies: [trivy-image-scan, trivy-filesystem-scan]
- name: simple-container
container:
image: alpine:3.20.3
command: [sh, -c]
args: ["echo test"]
- name: ls
container:
image: alpine:3.20.3
command: [sh, -c]
args:
- |
set -e
ls -la /
ls -la /shared-data
ls -la /shared-data/repo
volumeMounts:
- name: shared-data
mountPath: /shared-data
- name: git-clone
container:
image: ubuntu:24.10
command: [sh, -c]
args:
- |
set -e
apt update
apt install -y git
git clone -b main https://forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/Franz.Germann/fibonacci_go.git /shared-data/repo
echo git-clone task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data
- name: build
container:
image: gcr.io/kaniko-project/executor:v1.23.2
args:
[
"--dockerfile=Dockerfile",
"--context=/shared-data/repo/",
"--destination=gitea.cnoe.localtest.me/giteaadmin/fibonacci_go:latest",
"--skip-tls-verify"
]
volumeMounts:
- name: shared-data
mountPath: /shared-data
- name: docker-config
mountPath: /kaniko/.docker/
- name: unit-tests
container:
image: golang:1.23.2
command: [sh, -c]
args:
- |
set -e
cd /shared-data/repo
go test ./... -v
echo unit-test task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data
# How to extract artifacts
- name: lint-scan
container:
image: golangci/golangci-lint:v1.61.0
command: [sh, -c]
args:
- |
set -e
cd /shared-data/repo
golangci-lint run ./... --out-format=json --timeout 5m --issues-exit-code 1
echo lint-scan task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data
- name: trivy-filesystem-scan
container:
image: aquasec/trivy:0.56.2
command: [sh, -c]
args:
- |
set -e
trivy fs --scanners license,vuln,misconfig,secret /shared-data/repo
echo trivy-filesystem-scan task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data
- name: trivy-image-scan
container:
image: aquasec/trivy:0.56.2
command: [sh, -c]
args:
- |
set -e
TRIVY_INSECURE=true trivy image --scanners license,vuln,secret gitea.cnoe.localtest.me/giteaadmin/fibonacci_go:latest
TRIVY_INSECURE=true trivy image --image-config-scanners secret,misconfig gitea.cnoe.localtest.me/giteaadmin/fibonacci_go:latest
echo trivy-image-scan task completed

View file

@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: build-and-push-image-template
spec:
entrypoint: build
templates:
- name: build
inputs:
parameters:
- name: dockerfile-name
- name: image-destination
container:
image: gcr.io/kaniko-project/executor:v1.23.2
args:
[
"--dockerfile={{inputs.parameters.dockerfile-name}}",
"--context=/shared-data/repo/",
"--destination={{inputs.parameters.image-destination}}",
"--skip-tls-verify"
]
volumeMounts:
- name: shared-data
mountPath: /shared-data
- name: docker-config
mountPath: /kaniko/.docker/

View file

@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: git-clone-template
spec:
entrypoint: git-clone
templates:
- name: git-clone
inputs:
parameters:
- name: git-repo
container:
image: ubuntu:24.10
command: [sh, -c]
args:
- |
set -e
apt update
apt install -y git
git clone -b main {{inputs.parameters.git-repo}} /shared-data/repo
echo git-clone task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data

View file

@ -1,22 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: lint-scan-template
spec:
entrypoint: lint-scan
templates:
- name: lint-scan
container:
image: golangci/golangci-lint:v1.61.0
command: [sh, -c]
args:
- |
set -e
cd /shared-data/repo
golangci-lint run ./... --out-format=json --timeout 5m --issues-exit-code 1
echo lint-scan task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data

View file

@ -1,21 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: trivy-filesystem-scan-template
spec:
entrypoint: trivy-filesystem-scan
templates:
- name: trivy-filesystem-scan
container:
image: aquasec/trivy:0.56.2
command: [sh, -c]
args:
- |
set -e
trivy fs --scanners license,vuln,misconfig,secret /shared-data/repo
echo trivy-filesystem-scan task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data

View file

@ -1,22 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: trivy-image-scan-template
spec:
entrypoint: trivy-image-scan
templates:
- name: trivy-image-scan
inputs:
parameters:
- name: image
container:
image: aquasec/trivy:0.56.2
command: [sh, -c]
args:
- |
set -e
TRIVY_INSECURE=true trivy image --scanners license,vuln,secret {{inputs.parameters.image}}
TRIVY_INSECURE=true trivy image --image-config-scanners secret,misconfig {{inputs.parameters.image}}
echo trivy-image-scan task completed

View file

@ -1,22 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: unit-tests-template
spec:
entrypoint: unit-tests
templates:
- name: unit-tests
container:
image: golang:1.23.2
command: [sh, -c]
args:
- |
set -e
cd /shared-data/repo
go test ./... -v
echo unit-test task completed
volumeMounts:
- name: shared-data
mountPath: /shared-data

16
cmd/main.go Normal file
View file

@ -0,0 +1,16 @@
package main
import (
"apps/internal/http"
"log"
)
func main() {
err := http.StartServer()
log.Fatal(err)
//fmt.Println("20: ", fibonacci.Fibonacci(20))
//fmt.Println("200: ", fibonacci.FibonacciBig(200))
}

View file

@ -1,7 +0,0 @@
{
"auths": {
"https://gitea.cnoe.localtest.me": {
"auth": "Z2l0ZWFBZG1pbjozbUp5QkFYSUhqT3JPWlZaYlROMjlRPT0="
}
}
}

37
fib.go
View file

@ -1,37 +0,0 @@
package fib
import "math/big"
// Fibonacci calculates Fibonacci number.
// This function generated correct values from 0 to 93 sequence number.
// For bigger values use FibonacciBig function.
func Fibonacci(n uint) uint64 {
if n <= 1 {
return uint64(n)
}
var n2, n1 uint64 = 0, 1
for i := uint(2); i < n; i++ {
n2, n1 = n1, n1+n2
}
return n2 + n1
}
// FibonacciBig calculates Fibonacci number using bit.Int.
// For the sequence numbers below 94, it is recommended to use Fibonacci function as it is more efficient.
func FibonacciBig(n uint) *big.Int {
if n <= 1 {
return big.NewInt(int64(n))
}
var n2, n1 = big.NewInt(0), big.NewInt(1)
for i := uint(1); i < n; i++ {
n2.Add(n2, n1)
n1, n2 = n2, n1
}
return n1
}

39
go.mod
View file

@ -1,3 +1,38 @@
module forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/DevFW/fibonacci_go
module apps
go 1.23.2
go 1.22.2
require github.com/gin-gonic/gin v1.10.0
require (
github.com/bytedance/sonic v1.12.5 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.23.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

113
go.sum Normal file
View file

@ -0,0 +1,113 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bytedance/sonic v1.12.5 h1:hoZxY8uW+mT+OpkcUWw4k0fDINtOcVavEsGfzwzFU/w=
github.com/bytedance/sonic v1.12.5/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.1 h1:1GgorWTqf12TA8mma4DDSbaQigE2wOgQo7iCjjJv3+E=
github.com/bytedance/sonic/loader v0.2.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chenjiandongx/ginprom v0.0.0-20210617023641-6c809602c38a h1:yTfhjWYoPomJkHVArtNHpo36FuOa6Kc2ZjTLvyyQ5Lg=
github.com/chenjiandongx/ginprom v0.0.0-20210617023641-6c809602c38a/go.mod h1:lINNCb1ZH3c0uL/9ApaQ8muR4QILsi0STj8Ojt8ZmwU=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA=
github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o=
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc=
github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg=
golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
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.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=

76
internal/fibonacci/fib.go Normal file
View file

@ -0,0 +1,76 @@
package fibonacci
import (
"errors"
"fmt"
"math/big"
)
// Fibonacci calculates Fibonacci number.
// This function generated correct values from 0 to 93 sequence number.
// For bigger values use FibonacciBig function.
func Fibonacci(n uint) uint64 {
if n <= 1 {
return uint64(n)
}
var n2, n1 uint64 = 0, 1
for i := uint(2); i < n; i++ {
n2, n1 = n1, n1+n2
}
return n2 + n1
}
// FibonacciBig calculates Fibonacci number using bit.Int.
// For the sequence numbers below 94, it is recommended to use Fibonacci function as it is more efficient.
func FibonacciBig(n uint) *big.Int {
if n <= 1 {
return big.NewInt(int64(n))
}
var n2, n1 = big.NewInt(0), big.NewInt(1)
for i := uint(1); i < n; i++ {
n2.Add(n2, n1)
n1, n2 = n2, n1
}
return n1
}
func FibonacciFromString(str string) (*big.Int, error) {
n := new(big.Int)
n, ok := n.SetString(str, 10)
if !ok {
return nil, errors.New("ConvertError")
}
if n.Sign() != 1 {
return big.NewInt(int64(n.Int64())), nil
}
// Initialize two big ints with the first two numbers in the sequence.
a := big.NewInt(0)
b := big.NewInt(1)
// Loop while a is smaller than 1e100.
for i := int64(1); i <= n.Int64(); i++ {
// Compute the next Fibonacci number, storing it in a.
a.Add(a, b)
// Swap a and b so that b is the next number in the sequence.
a, b = b, a
}
fmt.Println(a) // 100-digit Fibonacci number
// Test a for primality.
// (ProbablyPrimes' argument sets the number of Miller-Rabin
// rounds to be performed. 20 is a good value.)
fmt.Println(a.ProbablyPrime(20))
return a, nil
}

View file

@ -1,4 +1,4 @@
package fib
package fibonacci
import "testing"

39
internal/http/server.go Normal file
View file

@ -0,0 +1,39 @@
package http
import (
"apps/internal/fibonacci"
"fmt"
"net/http"
//"github.com/chenjiandongx/ginprom"
"github.com/gin-gonic/gin"
//"github.com/prometheus/client_golang/prometheus/promhttp"
)
func StartServer() error {
r := gin.Default()
//r.Use(ginprom.PromMiddleware(nil))
r.GET("/fibonacci", CalculateFibonacci)
//r.GET("/metrics", gin.WrapH(promhttp.Handler()))
return r.Run(":9090")
}
func CalculateFibonacci(c *gin.Context) {
numberstr := c.Query("number")
result, err := fibonacci.FibonacciFromString(numberstr)
if err != nil {
c.AbortWithStatus(http.StatusBadRequest)
return
}
c.JSON(200, gin.H{
"result": fmt.Sprint(result),
})
}

View file

@ -1,36 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIGNDCCBBygAwIBAgIUNEvbJ9DWHN6yFqZHreKPK0HCEhowDQYJKoZIhvcNAQEL
BQAwgYkxCzAJBgNVBAYTAkFCMRIwEAYDVQQIDAlTdGF0ZU5hbWUxETAPBgNVBAcM
CENpdHlOYW1lMRQwEgYDVQQKDAtDb21wYW55TmFtZTEbMBkGA1UECwwSQ29tcGFu
eVNlY3Rpb25OYW1lMSAwHgYDVQQDDBdnaXRlYS5jbm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