primeira entrega
This commit is contained in:
commit
bd6d9d8b7a
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
# Contenedor para compilar
|
||||
FROM golang:alpine AS builder
|
||||
RUN apk add --update git
|
||||
|
||||
# Configurar Go modules y compilar
|
||||
WORKDIR /go/src/tr4ck.net/xenerador_contrasinais/
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o app .
|
||||
|
||||
# Contenedor para ejecutar
|
||||
FROM alpine:latest
|
||||
RUN addgroup -S user && adduser -S user -G user
|
||||
|
||||
WORKDIR /srv/xenerador_contrasinais/
|
||||
COPY --from=builder /go/src/tr4ck.net/xenerador_contrasinais/app .
|
||||
COPY templates/ ./templates/
|
||||
COPY palabras.txt .
|
||||
|
||||
USER user
|
||||
ENV GIN_MODE=release
|
||||
EXPOSE 8080
|
||||
CMD ["./app"]
|
18
README.md
Normal file
18
README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Xenerador de contrasinais
|
||||
|
||||
Xenera frases en galego para usar como contrasinais do estilo: correct horse battery staple.
|
||||
Seguindo as ensinanzas de [xkcd](https://xkcd.com/936/).
|
||||
|
||||
## Build:
|
||||
```
|
||||
docker build -t contrasinais .
|
||||
```
|
||||
|
||||
## Run:
|
||||
```
|
||||
docker run -d \
|
||||
-p 8080:8080 \
|
||||
--name contrasinais \
|
||||
--restart=unless-stopped \
|
||||
contrasinais
|
||||
```
|
58406
dict/Galego.dic
Normal file
58406
dict/Galego.dic
Normal file
File diff suppressed because it is too large
Load Diff
33
go.mod
Normal file
33
go.mod
Normal file
@ -0,0 +1,33 @@
|
||||
module tr4ck.net/xenerador_contrasinais
|
||||
|
||||
go 1.23.6
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.12.9 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.3 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||
github.com/gin-contrib/sse v1.0.0 // indirect
|
||||
github.com/gin-gonic/gin v1.10.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.25.0 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 // 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/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.14.0 // indirect
|
||||
golang.org/x/crypto v0.33.0 // indirect
|
||||
golang.org/x/net v0.35.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
78
go.sum
Normal file
78
go.sum
Normal file
@ -0,0 +1,78 @@
|
||||
github.com/bytedance/sonic v1.12.9 h1:Od1BvK55NnewtGaJsTDeAOSnLVO2BTSLOe0+ooKokmQ=
|
||||
github.com/bytedance/sonic v1.12.9/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.3 h1:yctD0Q3v2NOGfSWPLPvG2ggA2kV6TS6s4wioyEqssH0=
|
||||
github.com/bytedance/sonic/loader v0.2.3/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
||||
github.com/cloudwego/base64x v0.1.5/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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
||||
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
|
||||
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/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.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
|
||||
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
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/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/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/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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
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/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
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.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.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.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
|
||||
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
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=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
18199
palabras.txt
Normal file
18199
palabras.txt
Normal file
File diff suppressed because it is too large
Load Diff
112
templates/index.tmpl
Normal file
112
templates/index.tmpl
Normal file
@ -0,0 +1,112 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="gz">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Xenerador de contrasinais</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
background: linear-gradient(135deg, #121212, #1e1e1e);
|
||||
color: #d1d1d1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
.container {
|
||||
background: #242424;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.3);
|
||||
text-align: center;
|
||||
max-width: 420px;
|
||||
width: 100%;
|
||||
margin-top: 25px;
|
||||
border: 1px solid #3a3a3a;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.8rem;
|
||||
margin-bottom: 15px;
|
||||
color: #00bcd4;
|
||||
text-shadow: 0px 0px 5px rgba(0, 188, 212, 0.5);
|
||||
font-weight: 600;
|
||||
}
|
||||
.password-box {
|
||||
background: #333;
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 1.4rem;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
word-break: break-all;
|
||||
text-align: center;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #00bcd4;
|
||||
}
|
||||
.button {
|
||||
background: #00bcd4;
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
padding: 10px 16px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
transition: background 0.3s, box-shadow 0.3s;
|
||||
font-weight: 500;
|
||||
}
|
||||
.button:hover {
|
||||
background: #008ba3;
|
||||
box-shadow: 0px 2px 8px rgba(0, 188, 212, 0.5);
|
||||
}
|
||||
a {
|
||||
color: #00bcd4;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
a:hover {
|
||||
color: #008ba3;
|
||||
text-decoration: underline;
|
||||
}
|
||||
footer {
|
||||
margin-top: auto;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
font-size: 0.9rem;
|
||||
color: #a1a1a1;
|
||||
font-weight: 400;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>
|
||||
Xenerador de contrasinais
|
||||
</h1>
|
||||
<p>
|
||||
Xenera frases en galego para usar como contrasinais do estilo:
|
||||
<a href="https://xkcd.com/936/">correct horse battery staple</a>.
|
||||
</p>
|
||||
|
||||
<div class="password-box">
|
||||
{{ .password }}
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<label>Cantidade de palabras:</label><br>
|
||||
<input type="text" id="num" name="num" value="4"><br>
|
||||
<label>Separador:</label><br>
|
||||
<input type="text" id="sep" name="sep" value=""><br><br>
|
||||
<input class="button" type="submit" value="xenerar">
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
Feito con ❤️ por <a href="https://tr4ck.net/~sergio">serxoz</a> no 2025.
|
||||
</footer>
|
||||
</html>
|
126
xenerador.go
Normal file
126
xenerador.go
Normal file
@ -0,0 +1,126 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// devolve un array co listado de palabros do arquivo palabras.txt
|
||||
func read_words() []string {
|
||||
readFile, err := os.Open("palabras.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer readFile.Close()
|
||||
|
||||
fileScanner := bufio.NewScanner(readFile)
|
||||
fileScanner.Split(bufio.ScanLines)
|
||||
var fileLines []string
|
||||
|
||||
for fileScanner.Scan() {
|
||||
fileLines = append(fileLines, fileScanner.Text())
|
||||
}
|
||||
|
||||
return fileLines
|
||||
}
|
||||
|
||||
// devolve unha palabra random
|
||||
func random_word(list []string) string {
|
||||
return list[rand.Intn(len(list))]
|
||||
}
|
||||
|
||||
// monta a frase a usar como contrasinal
|
||||
func generate_password(list []string, cantidade int, separator string) string {
|
||||
phrase := ""
|
||||
for i := range cantidade {
|
||||
if i == cantidade-1 {
|
||||
// ultimo elemento
|
||||
phrase = phrase + random_word(list)
|
||||
} else {
|
||||
phrase = phrase + random_word(list) + separator
|
||||
}
|
||||
}
|
||||
return phrase
|
||||
}
|
||||
|
||||
// xenera resposta
|
||||
type resposta struct {
|
||||
code int
|
||||
chave string
|
||||
valor string
|
||||
}
|
||||
|
||||
func generate_response(c *gin.Context, listado []string) resposta {
|
||||
resp := resposta{}
|
||||
|
||||
num := c.Query("num")
|
||||
sep := c.Query("sep")
|
||||
if num == "" {
|
||||
num = "4" // cantidade por defecto
|
||||
}
|
||||
if sep == "" {
|
||||
sep = " " // separador por defecto
|
||||
}
|
||||
|
||||
isNumber := regexp.MustCompile(`^\d*$`)
|
||||
if !isNumber.MatchString(num) {
|
||||
resp.code = 400
|
||||
resp.chave = "error"
|
||||
resp.valor = "O parámetro 'num' ten que ser un número."
|
||||
} else {
|
||||
// xenera unha frase de 'num' palabras
|
||||
n, _ := strconv.Atoi(num) // o erro non fai falta, foi comprobado no regexp
|
||||
|
||||
if n >= 128 {
|
||||
// limitase a sacho
|
||||
n = 128
|
||||
}
|
||||
resp.code = 200
|
||||
resp.chave = "password"
|
||||
resp.valor = generate_password(listado, n, sep)
|
||||
}
|
||||
|
||||
// resp.code sera o 200 e logo chave e valor o JSON do gin.H
|
||||
// c.JSON(200, gin.H{
|
||||
// "password": generate_password(listado, n, sep),
|
||||
// })
|
||||
return resp
|
||||
}
|
||||
|
||||
func main() {
|
||||
// lemos a memoria o arquivo de palabras
|
||||
listado := read_words()
|
||||
|
||||
// arrancamos gin
|
||||
r := gin.Default()
|
||||
r.LoadHTMLGlob("templates/*")
|
||||
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
|
||||
// /pass?num=4&sep=-
|
||||
r.GET("/pass", func(c *gin.Context) {
|
||||
resp := generate_response(c, listado)
|
||||
c.JSON(resp.code, gin.H{
|
||||
resp.chave: resp.valor,
|
||||
})
|
||||
})
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
resp := generate_response(c, listado)
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
resp.chave: resp.valor,
|
||||
})
|
||||
})
|
||||
|
||||
r.Run() //listen and serve on 0.0.0.0:8080
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user