├── .gitattributes
├── LICENSE
├── README.md
└── src
├── .gitignore
├── Docker-compose.yaml
├── Dockerfile
├── database
├── adminip.txt
├── inicialize.sql
└── publications.db
├── go.mod
├── go.sum
├── main.go
├── public
├── .DS_Store
├── script
│ ├── .DS_Store
│ ├── getPublication.ts
│ ├── post.ts
│ ├── prism.js.zip
│ └── tsconfig.json
└── style
│ ├── prism.css.zip
│ └── style.css
├── src
├── controllers
│ ├── controllers.go
│ ├── newPost.go
│ └── renderStuff.go
├── dataControll
│ ├── addPublication.go
│ ├── dataControl.go
│ ├── getOnlyOnePublication.go
│ ├── getPublications.go
│ └── getSizeOfQuery.go
├── router
│ └── routes.go
└── stuff
│ ├── const.go
│ ├── func.go
│ └── types.go
└── view
├── denegado.html
├── home.html
├── post.html
└── template.html
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
18 |
9 |
10 | # this is how looks the article
11 |
12 |
13 |
14 | # How to use this blog
15 |
16 |
17 | First you need to clone the blog,
18 | after that you need to encrypt your ipv6 to sha256 and
19 | copy and replace the text with your ip in the file [adminip.txt](https://github.com/ranon-rat/makingABlogWithGolang/blob/main/src/adminip.txt)
20 | then of that you need to push it in any cloud service like heroku where I have it hosted.
21 |
22 | 
23 | Now you only need to make your first publication to the route `admin/postfile` push the title , the url image and the body in markdown obviously
24 |
25 | 
26 |
27 | And thats all you need, now go to visit your page and i have nothing to say now so bye
28 |
--------------------------------------------------------------------------------
/src/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | /public/script/*.js
3 | /public/style/prism.css
4 | .DS_Store
5 | */.DS_Store
--------------------------------------------------------------------------------
/src/Docker-compose.yaml:
--------------------------------------------------------------------------------
1 |
2 | version: "3"
3 |
4 | services:
5 | blog:
6 | build: .
7 | ports:
8 | - 8080:8080
--------------------------------------------------------------------------------
/src/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:alpine
2 |
3 | COPY . ./blog
4 | WORKDIR /go/blog/
5 | RUN apk update && apk upgrade && apk add build-base
6 | # install the dependencies
7 | RUN apk add sqlite && apk add npm && apk add zip
8 | RUN npm install -g typescript
9 | # init the database
10 | RUN cat database/inicialize.sql | sqlite3 database/publications.db
11 |
12 | # compile some stuff
13 | WORKDIR /go/blog/public/script
14 |
15 | RUN tsc *.ts
16 | RUN rm -rf *.ts
17 | RUN unzip *.zip
18 | RUN unzip *.zip ;rm -rf *.zip
19 | WORKDIR /go/blog/public/style
20 | # delete some things
21 | RUN unzip *.zip ;rm -rf *.zip
22 |
23 | WORKDIR /go/blog/
24 | #compile
25 | RUN go build main.go
26 | # delete
27 | RUN rm -rf database/inicialize.sql
28 | RUN apk del npm && apk del zip
29 |
30 | CMD ["./main"]
31 |
--------------------------------------------------------------------------------
/src/database/adminip.txt:
--------------------------------------------------------------------------------
1 | 40ab56780f32cc7ce1373a68847527612a52a563c11197b997d834aada9f05ca
--------------------------------------------------------------------------------
/src/database/inicialize.sql:
--------------------------------------------------------------------------------
1 | -- its for sqlite3
2 | CREATE TABLE publ
3 | (
4 | id INTEGER PRIMARY KEY,
5 | title TEXT NOT NULL,
6 | mineatura TEXT NOT NULL,
7 | body TEXT NOT NULL
8 | );
9 |
--------------------------------------------------------------------------------
/src/database/publications.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ranon-rat/makingABlogWithGolang/1d7be59c36bb5d8ee7714f5651b4e8c80055878e/src/database/publications.db
--------------------------------------------------------------------------------
/src/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/ranon-rat/blog
2 |
3 | go 1.15
4 |
5 | require (
6 | github.com/gomarkdown/markdown v0.0.0-20201113031856-722100d81a8e
7 | github.com/gorilla/mux v1.8.0
8 | github.com/mattn/go-sqlite3 v1.14.6
9 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
10 |
11 | )
12 |
--------------------------------------------------------------------------------
/src/go.sum:
--------------------------------------------------------------------------------
1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
8 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
9 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
10 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
11 | github.com/go-pg/pg v8.0.7+incompatible h1:ty/sXL1OZLo+47KK9N8llRcmbA9tZasqbQ/OO4ld53g=
12 | github.com/go-pg/pg/v10 v10.7.3 h1:oL/Hz5MJie/9epmwxlZjfReO+2wlLPOK6BeGb9I+XHk=
13 | github.com/go-pg/pg/v10 v10.7.3/go.mod h1:UsDYtA+ihbBNX1OeIvDejxkL4RXzL3wsZYoEv5NUEqM=
14 | github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4mU=
15 | github.com/go-pg/zerochecker v0.2.0/go.mod h1:NJZ4wKL0NmTtz0GKCoJ8kym6Xn/EQzXRl2OnAe7MmDo=
16 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
17 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
18 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
19 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
20 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
21 | github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
22 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
23 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
24 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
25 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
26 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
27 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
28 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
29 | github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
30 | github.com/gomarkdown/markdown v0.0.0-20201113031856-722100d81a8e h1:/Y3B7hM9H3TOWPhe8eWGBGS4r09pjvS5Z0uoPADyjmU=
31 | github.com/gomarkdown/markdown v0.0.0-20201113031856-722100d81a8e/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
32 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
33 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
34 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
35 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
36 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
37 | github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
38 | github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
39 | github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
40 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
41 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
42 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
43 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
44 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
45 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
46 | github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8=
47 | github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
48 | github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
49 | github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
50 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
51 | github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
52 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
53 | github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
54 | github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
55 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
56 | github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
57 | github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
58 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
59 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
60 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
61 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
62 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
63 | github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
64 | github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
65 | github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94=
66 | github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ=
67 | github.com/vmihailenco/msgpack/v4 v4.3.11/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
68 | github.com/vmihailenco/msgpack/v5 v5.0.0 h1:nCaMMPEyfgwkGc/Y0GreJPhuvzqCqW+Ufq5lY7zLO2c=
69 | github.com/vmihailenco/msgpack/v5 v5.0.0/go.mod h1:HVxBVPUK/+fZMonk4bi1islLa8V3cfnBug0+4dykPzo=
70 | github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
71 | github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc=
72 | github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
73 | go.opentelemetry.io/otel v0.14.0 h1:YFBEfjCk9MTjaytCNSUkp9Q8lF7QJezA06T71FbQxLQ=
74 | go.opentelemetry.io/otel v0.14.0/go.mod h1:vH5xEuwy7Rts0GNtsCW3HYQoZDY+OmBJ6t1bFGGlxgw=
75 | golang.org/dl v0.0.0-20190829154251-82a15e2f2ead h1:jeP6FgaSLNTMP+Yri3qjlACywQLye+huGLmNGhBzm6k=
76 | golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
77 | golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
78 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
79 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
80 | golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 h1:phUcVbl53swtrUN8kQEXFhUxPlIlWyBfKmidCu7P95o=
81 | golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
82 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
83 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
84 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
85 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
86 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
87 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
88 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
89 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
90 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
91 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
92 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
93 | golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
94 | golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
95 | golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
96 | golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
97 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
98 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
99 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
100 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
101 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
102 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
103 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
104 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
105 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
106 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
107 | golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
108 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
109 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
110 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
111 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
112 | golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
113 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
114 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
115 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
116 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
117 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
118 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
119 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
120 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
121 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
122 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
123 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
124 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
125 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
126 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
127 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
128 | google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
129 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
130 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
131 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
132 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
133 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
134 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
135 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
136 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
137 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
138 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
139 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
140 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
141 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
142 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
143 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
144 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
145 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
146 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
147 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
148 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
149 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
150 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
151 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
152 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
153 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
154 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
155 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
156 | mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
157 | mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
158 |
--------------------------------------------------------------------------------
/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 |
6 | "github.com/ranon-rat/blog/src/router"
7 | )
8 |
9 | // y el main obviamente
10 | func main() {
11 |
12 | log.Println("starting server")
13 | router.Routes()
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/public/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ranon-rat/makingABlogWithGolang/1d7be59c36bb5d8ee7714f5651b4e8c80055878e/src/public/.DS_Store
--------------------------------------------------------------------------------
/src/public/script/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ranon-rat/makingABlogWithGolang/1d7be59c36bb5d8ee7714f5651b4e8c80055878e/src/public/script/.DS_Store
--------------------------------------------------------------------------------
/src/public/script/getPublication.ts:
--------------------------------------------------------------------------------
1 | // @ts-nocheck
2 | interface Pub {
3 | Cantidad: number;
4 | Publications: {
5 | id: number;
6 | title: string;
7 | mineatura: string;
8 | bodyOfDocument: string;
9 | }[];
10 | Size: number;
11 | }
12 |
13 | async function NewPublications() {
14 | let urlApi: string =
15 | "api" + "/" + window.location.pathname.replace(/\//gi, "");
16 | let publication: Pub | string = {
17 | Publications: [
18 | {
19 | id: 0,
20 | title: "",
21 | mineatura: "",
22 | bodyOfDocument: "",
23 | },
24 | ],
25 | Size: 0,
26 | Cantidad: 0,
27 | };
28 |
29 | // this is only for get the api
30 | await fetch(urlApi)
31 | .then((r) => r.text())
32 | .then((data) => {
33 | publication = data;
34 | publication = JSON.parse(publication);
35 | });
36 |
37 | let d: any = document.getElementById("publications");
38 |
39 | // add the elements
40 | for (let i of publication.Publications) {
41 | // then add elements into the dom
42 | let element = `
43 |
66 |
67 | `;
68 |
69 | d.innerHTML += element;
70 | }
71 | let pagePublications: any = document.getElementById("pagePublications");
72 | for (
73 | let i: number = 1;
74 | i <= publication.Size / publication.Cantidad + 1;
75 | i++
76 | ) {
77 | let Element: string = `
78 |
79 |
80 |
81 |
85 |
86 | `;
87 |
88 | pagePublications.innerHTML += Element;
89 | console.log(i); // this supose to be you
90 | }
91 | }
92 | NewPublications();
93 |
--------------------------------------------------------------------------------
/src/public/script/post.ts:
--------------------------------------------------------------------------------
1 | // @ts-nocheck
2 | interface Formulario {
3 | title: any;
4 | mineatura: any;
5 | bodyOfDocument: any;
6 | }
7 |
8 | async function sendDocument() {
9 | let f: Formulario = {
10 | title: document.getElementById("titulo")?.innerText,
11 | mineatura: document.getElementById("mineatura")?.innerText,
12 | bodyOfDocument: document.getElementById("bodyOfMessage")?.value,
13 | };
14 |
15 | if (!f.title || !f.mineatura || !f.bodyOfDocument) {
16 | alert("you need to define everything");
17 | return;
18 | }
19 | if (f.bodyOfDocument.length >= 100000) {
20 | alert("sorry but is too bigger for send that to the server");
21 | return;
22 | }
23 |
24 | fetch(window.location.pathname, {
25 | method: "POST",
26 | body: JSON.stringify(f),
27 | headers: {
28 | "Content-Type": "application/json",
29 | },
30 | });
31 | document.getElementById("titulo")?.innerText = "";
32 | document.getElementById("mineatura")?.innerText = "";
33 | document.getElementById("bodyOfMessage")?.value = "";
34 |
35 | console.log(f);
36 | }
37 |
--------------------------------------------------------------------------------
/src/public/script/prism.js.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ranon-rat/makingABlogWithGolang/1d7be59c36bb5d8ee7714f5651b4e8c80055878e/src/public/script/prism.js.zip
--------------------------------------------------------------------------------
/src/public/script/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */
4 |
5 | /* Basic Options */
6 | // "incremental": true, /* Enable incremental compilation */
7 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9 | // "lib": [], /* Specify library files to be included in the compilation. */
10 | // "allowJs": true, /* Allow javascript files to be compiled. */
11 | // "checkJs": true, /* Report errors in .js files. */
12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13 | // "declaration": true, /* Generates corresponding '.d.ts' file. */
14 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15 | // "sourceMap": true, /* Generates corresponding '.map' file. */
16 | // "outFile": "./", /* Concatenate and emit output to single file. */
17 | // "outDir": "./", /* Redirect output structure to the directory. */
18 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19 | // "composite": true, /* Enable project compilation */
20 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21 | // "removeComments": true, /* Do not emit comments to output. */
22 | // "noEmit": true, /* Do not emit outputs. */
23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26 |
27 | /* Strict Type-Checking Options */
28 | "strict": true, /* Enable all strict type-checking options. */
29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30 | // "strictNullChecks": true, /* Enable strict null checks. */
31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36 |
37 | /* Additional Checks */
38 | // "noUnusedLocals": true, /* Report errors on unused locals. */
39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */
40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
43 |
44 | /* Module Resolution Options */
45 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
46 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
47 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
48 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
49 | // "typeRoots": [], /* List of folders to include type definitions from. */
50 | // "types": [], /* Type declaration files to be included in compilation. */
51 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
52 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
53 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
54 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55 |
56 | /* Source Map Options */
57 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61 |
62 | /* Experimental Options */
63 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65 |
66 | /* Advanced Options */
67 | "skipLibCheck": true, /* Skip type checking of declaration files. */
68 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/public/style/prism.css.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ranon-rat/makingABlogWithGolang/1d7be59c36bb5d8ee7714f5651b4e8c80055878e/src/public/style/prism.css.zip
--------------------------------------------------------------------------------
/src/public/style/style.css:
--------------------------------------------------------------------------------
1 | body{
2 | background-color:#000;
3 | color:#fff;
4 | font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
5 | margin: 0px !important;
6 | }
7 | * {
8 | -webkit-box-sizing: border-box;
9 | -moz-box-sizing: border-box;
10 | box-sizing: border-box;
11 | }
12 |
13 | pre{
14 | width:59em;
15 | border-radius: 10px;
16 | background-color:#2d2d2d;
17 |
18 |
19 | }
20 | code{
21 |
22 | background-color:#2d2d2d;
23 | width:59em;
24 | }
25 |
26 | div{
27 | margin:4px !important;
28 | margin-top:10px;
29 | }
30 | table{
31 |
32 | width: 100%;
33 | border-spacing: 0;
34 | }
35 | th, td,tbody,thead {
36 | border:1px solid #3b434b;
37 | border-spacing: 0;
38 | padding: 6px 13px;
39 |
40 | }
41 | td{
42 | text-align:center;
43 | }
44 | #content img{
45 | width:60em;
46 | }
47 | .contenedor{
48 | border-style:solid;
49 | }
50 | .publications div {
51 |
52 | text-decoration: none;
53 | border-radius: 10px;
54 | width:100%;
55 | background-color: rgb(19, 19, 19);
56 |
57 |
58 | }
59 | .about{
60 | background-size: 100% 100%;
61 | height: 20em;
62 | }
63 | .publicationContent{
64 | height: 8em;
65 | }
66 | a{
67 | text-decoration: none;
68 | color:rgb(90, 0, 235);
69 | }
70 |
71 | .publicationContent img{
72 | float:right;
73 | height: 8em;
74 | border-radius: 10px;
75 | }
76 | .aboutPubication{
77 | bottom: 10em;
78 | }
79 | .aboutPubication p{
80 | color:rgb(165, 165, 165);
81 |
82 | }
83 | .buttonElementID{
84 |
85 | margin-left: auto;
86 | margin-right: auto;
87 |
88 | border-radius: 2px;
89 | text-align: center;
90 | background-color: rgb(31, 30, 30);
91 | width: 4em;
92 |
93 | display:inline-block;
94 | }
95 | .buttonElementID:hover{
96 | color:#000;
97 | background-color: rgb(255, 255, 255);
98 | }
99 | #content{
100 | width:59em;
101 | }
102 | #pagePublications{
103 | display: flex;
104 | justify-content: center;
105 | margin:4px;
106 |
107 | padding-top:10px;
108 | margin-left: auto;
109 | margin-right: auto;
110 | }
111 | #navegationVar {
112 | position: -webkit-sticky;
113 | position: sticky;
114 | top: 0;
115 |
116 |
117 | list-style-type: none;
118 | margin: 0;
119 | padding: 0;
120 | overflow: hidden;
121 | background-color: rgb(6, 4, 29);
122 |
123 | }
124 | #navegationVar li {
125 | float: left;
126 |
127 | }
128 | #navegationVar li a {
129 |
130 |
131 | display: block;
132 | color: white;
133 | text-align: center;
134 | padding: 16px 16px;
135 | text-decoration: none;
136 | }
137 | #navegationVar li a:hover {
138 |
139 | background-color: #111;
140 | color:white;
141 | }
142 | #gopher{
143 | float: right;
144 |
145 |
146 | }
147 | #body{
148 | border-style:none;
149 | }
150 | #inicio h1{
151 | font-size: 6em;
152 | }
153 | #inicio h2{
154 | font-size: 4em;
155 | }
156 | #titulo h1{
157 | font-size:7em;
158 | }
159 |
--------------------------------------------------------------------------------
/src/src/controllers/controllers.go:
--------------------------------------------------------------------------------
1 | package controllers
2 |
3 | import (
4 | "encoding/json"
5 | "log"
6 | "net/http"
7 | "strconv"
8 |
9 | "github.com/gorilla/mux"
10 | "github.com/ranon-rat/blog/src/dataControll"
11 | "github.com/ranon-rat/blog/src/stuff"
12 | )
13 |
14 | // this only is for the styles and script
15 | func Check(c chan bool, d stuff.Document) {
16 | _, err := http.Get(d.Mineatura)
17 | log.Println(d, err)
18 | c <- d.Body == "" || d.Title == "" || d.Mineatura == "" || err != nil
19 | }
20 |
21 | // this is the ap
22 |
23 | func Api(w http.ResponseWriter, r *http.Request) {
24 | // only send this
25 | // this is for use the apis
26 | min, _ := strconv.Atoi(mux.Vars(r)["page"])
27 |
28 |
29 | // concurrency communication
30 | //the db management
31 | sizeChan, dChan := make(chan int), make(chan []stuff.Document)
32 |
33 | // we use this function only one time so, im only usign a anon function 😩
34 |
35 | go dataControll.GetPublications(min, dChan)
36 |
37 | go dataControll.GetTheSizeOfTheQuery(sizeChan)
38 |
39 |
40 | api := stuff.Publications{
41 | Cantidad: stuff.Cantidad,
42 | Publications: <-dChan,
43 | Size: <-sizeChan,
44 | }
45 | // send the json
46 | json.NewEncoder(w).Encode(api)
47 |
48 | }
49 |
50 | // hello there
51 | // this is only the setup
52 |
--------------------------------------------------------------------------------
/src/src/controllers/newPost.go:
--------------------------------------------------------------------------------
1 | package controllers
2 |
3 | import (
4 | "encoding/json"
5 | "io/ioutil"
6 | "log"
7 | "net/http"
8 | "strings"
9 | "time"
10 |
11 | "github.com/ranon-rat/blog/src/dataControll"
12 | "github.com/ranon-rat/blog/src/stuff"
13 | "golang.org/x/sync/errgroup"
14 | )
15 |
16 | // this is the post manager , with this you can do really interesting things
17 | func NewPost(w http.ResponseWriter, r *http.Request) {
18 | confB, err := ioutil.ReadFile("database/adminip.txt")
19 | conf := string(confB)
20 | // aqui solo es para ver los metodos
21 |
22 | cookie, err := r.Cookie("ip")
23 | if err != nil {
24 | cookie = &http.Cookie{
25 | Name: "ip",
26 | Value: r.Header.Get("x-forwarded-for"),
27 | Expires: time.Now().AddDate(1, 0, 0),
28 | }
29 | http.SetCookie(w, cookie)
30 |
31 | }
32 |
33 | // new things
34 | // go back to the normal
35 | if strings.Contains(conf, stuff.EncryptData(r.Header.Get("x-forwarded-for"))) || strings.Contains(conf, stuff.EncryptData(cookie.Value)) {
36 | switch r.Method {
37 | case "POST":
38 | // i need to do some data bases for do this
39 |
40 | // in the future i gonna do something with this
41 | d,controlErrors,cont:= stuff.Document{},errgroup.Group{},make(chan bool)
42 |
43 | // decode the bodyRequest
44 | json.NewDecoder(r.Body).Decode(&d)
45 |
46 | // this is for check if something is wrong
47 | go Check(cont, d)
48 | if <-cont {
49 | log.Println("fuck")
50 | return
51 | }
52 | controlErrors.Go(func() error {
53 | // add the publications
54 | return dataControll.AddPublication(d)
55 | })
56 | if err = controlErrors.Wait(); err != nil {
57 | log.Println(err)
58 | return
59 | }
60 | return
61 |
62 | case "GET":
63 |
64 | http.ServeFile(w, r, "view/post.html")
65 | return
66 |
67 | default:
68 | // solo acepta 2 metodos de request
69 | w.Write([]byte("ñao ñao voce es maricon"))
70 | break
71 | }
72 | return
73 | }
74 | //log.Println(conf)
75 | http.ServeFile(w, r, "view/denegado.html")
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/src/controllers/renderStuff.go:
--------------------------------------------------------------------------------
1 | package controllers
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | "text/template"
7 |
8 | "github.com/gomarkdown/markdown"
9 | "github.com/gomarkdown/markdown/parser"
10 | "github.com/gorilla/mux"
11 | "github.com/ranon-rat/blog/src/dataControll"
12 | "github.com/ranon-rat/blog/src/stuff"
13 | )
14 |
15 | func RenderMarkdown(p chan stuff.Document, publicationChan chan stuff.Document) {
16 | // lo que hace es parsear el markdown en html
17 | extensions := parser.CommonExtensions | parser.AutoHeadingIDs
18 | parser := parser.NewWithExtensions(extensions)
19 | // for now im doing this
20 | // but i want to use this with a db
21 |
22 | d := <-publicationChan
23 | // ya sabe, concurrencia
24 | // obtiene el markdown
25 | d.Body = string(markdown.ToHTML([]byte(d.Body), parser, nil))
26 | if d.Body==""{
27 | d=stuff.Document{
28 | Body:"
84 |
non-existent publication
",
29 | Title: "Something is wrong",
30 | }
31 | } // despues lo pasa a html
32 | p <- d // al final hace lo siguiente
33 |
34 | }
35 | func RenderInfo(w http.ResponseWriter, r *http.Request) {
36 |
37 |
38 | // get the id of the publication
39 | id,_ := strconv.Atoi(mux.Vars(r)["id"])
40 |
41 | publication ,document:= make(chan stuff.Document),make(chan stuff.Document)
42 | // then decode the markdown to html
43 |
44 |
45 |
46 | go dataControll.GetOnlyOnePublication(id, document)
47 |
48 | go RenderMarkdown(publication,document)
49 |
50 | t, _ := template.ParseFiles("view/template.html")
51 |
52 |
53 | // the goroutines are the best
54 | //aqui estamos usando templates para evitar que tener que estar usando otra cosa
55 |
56 | t.Execute(w, <-publication)
57 | }
58 |
--------------------------------------------------------------------------------
/src/src/dataControll/addPublication.go:
--------------------------------------------------------------------------------
1 | package dataControll
2 |
3 | import (
4 | "errors"
5 |
6 | "github.com/ranon-rat/blog/src/stuff"
7 |
8 | _ "github.com/mattn/go-sqlite3"
9 | )
10 |
11 |
12 | func AddPublication(e stuff.Document) error {
13 | q := `INSERT INTO
14 | publ(title,mineatura,body)
15 | values(?1,?2,?3);
16 | `
17 | db := GetConnection()
18 | defer db.Close()
19 | stm, err := db.Prepare(q)
20 | if err != nil {
21 |
22 | return err
23 | }
24 | defer stm.Close()
25 | r, _ := stm.Exec(&e.Title, &e.Mineatura, &e.Body)
26 |
27 | i, _ := r.RowsAffected()
28 | if i != 1 {
29 |
30 | return errors.New("se esperaba una sola fila omg")
31 | }
32 | return nil
33 | }
--------------------------------------------------------------------------------
/src/src/dataControll/dataControl.go:
--------------------------------------------------------------------------------
1 | package dataControll
2 |
3 | import (
4 | "database/sql"
5 | "fmt"
6 |
7 | _ "github.com/mattn/go-sqlite3"
8 | )
9 |
10 | func GetConnection() *sql.DB {
11 |
12 | db, err := sql.Open("sqlite3", "./database/publications.db")
13 |
14 | if err != nil {
15 | fmt.Println(err)
16 | }
17 | return db
18 | }
19 |
20 |
21 |
22 | // this is for get the size of the table
23 |
--------------------------------------------------------------------------------
/src/src/dataControll/getOnlyOnePublication.go:
--------------------------------------------------------------------------------
1 | package dataControll
2 |
3 | import (
4 | "github.com/ranon-rat/blog/src/stuff"
5 |
6 | _ "github.com/mattn/go-sqlite3"
7 | )
8 |
9 | func GetOnlyOnePublication(id int, aChan chan stuff.Document) {
10 | q := (`SELECT * FROM publ WHERE id=?1`)
11 | db := GetConnection()
12 | defer db.Close()
13 | p, _ := db.Query(q, id)
14 |
15 |
16 | defer p.Close()
17 | var d stuff.Document
18 | for p.Next() {
19 |
20 | p.Scan(&d.ID, &d.Title, &d.Mineatura, &d.Body)
21 |
22 | }
23 | aChan <- d
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/src/dataControll/getPublications.go:
--------------------------------------------------------------------------------
1 | package dataControll
2 |
3 | import (
4 | "github.com/ranon-rat/blog/src/stuff"
5 |
6 | _ "github.com/mattn/go-sqlite3"
7 | )
8 |
9 | func GetPublications(min int, pChan chan []stuff.Document) {
10 | sChan := make(chan int)
11 | go GetTheSizeOfTheQuery(sChan)
12 | size := <-sChan
13 | // este es el consultorio croe que se llamaba asi , ya no me acuerdo xd
14 | q := `
15 | SELECT * FROM publ
16 | WHERE rowid >=?1 AND rowid <=?2
17 | ORDER BY id DESC ;`
18 |
19 | /*
20 | aqui lo que basicamente hace es ordenar del mayor al menor
21 | */
22 | // aqui lo que hace es ordenar el resultado
23 | db := GetConnection()
24 | // aqui lo que hace es conectarse a la base de datos
25 | defer db.Close()
26 | //espera a cerrarse para evitar ciertos problemas de seguridad
27 | m, _ := db.Query(q, (size - (min * stuff.Cantidad)), (size-(min*stuff.Cantidad)+stuff.Cantidad)+1) // envia esto y la salida deb de ser la siguiente
28 |
29 | defer m.Close() // espera a cerrar el canal ( por razones de seguridad)
30 |
31 | var pubs []stuff.Document
32 | for m.Next() {
33 | // repasa la informacion,
34 | var d stuff.Document
35 | // cambia los valores de publication
36 | m.Scan(&d.ID, &d.Title, &d.Mineatura, &d.Body)
37 |
38 | pubs = append(pubs, d)
39 | // los agrega a una listaa
40 | }
41 |
42 | pChan <- pubs
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/src/dataControll/getSizeOfQuery.go:
--------------------------------------------------------------------------------
1 | package dataControll
2 |
3 | import (
4 | "log"
5 |
6 | _ "github.com/mattn/go-sqlite3"
7 | )
8 |
9 | func GetTheSizeOfTheQuery(sizeChan chan int){
10 | q := `SELECT COUNT(*) FROM publ`
11 | // como no he encontrado muchas maneras de encontrar el
12 | //tamaño de una tabla lo que hace aqui es basicamente seleccionar el maximo valor
13 | dataSize:=0
14 | db := GetConnection()
15 | defer db.Close()
16 | m, err := db.Query(q)
17 | if err!=nil{
18 | close(sizeChan)
19 | return
20 | }
21 |
22 | for m.Next() {
23 | if err=m.Scan(&dataSize);err!=nil{
24 | log.Println(err)
25 | close(sizeChan)
26 | return
27 |
28 | }
29 | }
30 | sizeChan<-dataSize
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/src/router/routes.go:
--------------------------------------------------------------------------------
1 | package router
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "os"
7 |
8 | "github.com/gorilla/mux"
9 | "github.com/ranon-rat/blog/src/controllers"
10 | )
11 |
12 | func Routes() {
13 | // aqui solo es para dar la salida de informacion
14 | r := mux.NewRouter()
15 | // REDIRIJE
16 | r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
17 | http.Redirect(w, r, "/1", 301)
18 | // yeah this is cool
19 | })
20 | // load the page
21 | r.HandleFunc(`/{page:[\d]+}`, func(w http.ResponseWriter, r *http.Request) {
22 | http.ServeFile(w, r, "view/home.html")
23 | })
24 | // send the files
25 | r.HandleFunc(`/public/{file:[\/\w\W]+?}`, func(w http.ResponseWriter, r *http.Request) {
26 | http.ServeFile(w, r, r.URL.Path[1:])
27 | })
28 | r.HandleFunc("/admin/postfile", controllers.NewPost)
29 | // get the info
30 | r.HandleFunc(`/api/{page:[\d]+}`, controllers.Api)
31 | // render the publication
32 |
33 | r.HandleFunc(`/publication/{id:[\d]+}`, controllers.RenderInfo)
34 | port, ok := os.LookupEnv("PORT")
35 |
36 | if !ok {
37 | port = "8080"
38 | }
39 | log.Println(http.ListenAndServe(":"+port, r))
40 | }
41 |
--------------------------------------------------------------------------------
/src/src/stuff/const.go:
--------------------------------------------------------------------------------
1 | package stuff
2 |
3 | const (
4 | Cantidad int = 9
5 | )
6 |
--------------------------------------------------------------------------------
/src/src/stuff/func.go:
--------------------------------------------------------------------------------
1 | package stuff
2 |
3 | import (
4 | "crypto/sha256"
5 | "encoding/hex"
6 | )
7 | func EncryptData(data string) string {
8 | sum := sha256.Sum256([]byte(data)) // we encript the data
9 |
10 | return hex.EncodeToString(sum[:])
11 | }
--------------------------------------------------------------------------------
/src/src/stuff/types.go:
--------------------------------------------------------------------------------
1 | package stuff
2 |
3 | type Document struct {
4 | ID int `json:"id"`
5 | Title string `json:"title"`
6 | Mineatura string `json:"mineatura"`
7 | Body string `json:"bodyOfDocument"`
8 | }
9 | type Publications struct {
10 | Size int `json:"Size"`
11 | Publications []Document `json:"Publications"`
12 | Cantidad int `json:"Cantidad"`
13 | }
14 |
--------------------------------------------------------------------------------
/src/view/denegado.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
11 | ñao ñao voce e gay
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/view/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
36 | blog in golang
37 |
41 |
42 |
38 |
39 |
40 |
43 | this is my blog
44 |
45 | well here we go
12 | title
13 |
14 | miniature(here you need to upload a url )
15 |
16 | body
17 |
20 |
21 |
22 |
23 |
24 |