Browse Source

Integrated build infos into the binary: fix #37 and cleaned up

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
437e314250
  1. 1
      .gitignore
  2. 3
      .travis.yml
  3. 1
      Makefile
  4. 3
      README.md
  5. 10
      build/info.sh
  6. 9
      handlers/handlers.go
  7. 11
      handlers/public.go
  8. 57
      static/src/About/About.js
  9. 3
      static/src/ShareX/ShareX.css
  10. 2
      static/src/ShareX/ShareX.js

1
.gitignore

@ -17,6 +17,7 @@ debug
/config.* /config.*
/handlers/static.go /handlers/static.go
/handlers/tmpls/tmpls.go /handlers/tmpls/tmpls.go
/util/version.go
/store/main.db /store/main.db
/releases /releases
/data /data

3
.travis.yml

@ -21,6 +21,3 @@ deploy:
file: "build/bintray.json" file: "build/bintray.json"
key: key:
secure: ErqvSFIlL3d9XuMj+T+hO6xZqll8Ubx0DEdHD6NJKi7sH7Be3b3/vUoPdAjdFOP70DhaccbncGCTPZ9hsNKdqYxZmuKx3WWwH4H4U5YdDIViXtH6+B5KdAmvdZIynaj+THQAbVAhr+QyvcqotNySPd3Ac1HCg2YAcUHme6y3FsiRJ79To80JWxTSR1G/oObmeoDn8R18wmH1gHl8KQ7ltC537Osb/H34bJ/hY94hRe8IEmoQE4yz/EP44kGXRb/F87i92y1mO081ZS1I1hs5Kbom43YoItqSVbJP/abPMyCsGDv2FGXaGqk5IVC1k+01pcAjqxCzMvXC272itc0E8OEWqE4qONN+m2S9tyALyOaUZ7j5meWLHQj49Rzo7XIWh1PvvEMovdl/wk/Oc9f0ZywPuvoRht5ZebgXbPWAMMNywwy0GKM4nU0DCyFm23mlzPh4iklo12gEUzq3YLc18RhAZuy4timeevrDCuJMQeQ3sqcQBKCQ+rdOxzVCKKl2sGpNaTJEYaHGT9KLCEGBLmvaB58RKgmGN6IIEwpxSm2SGoirfnQsr+DP+kaSvWPr6R/pZAhO1JzO+azaXvfr+hL2SMX6U7j5+SDmFGIFDwxok7ny1QUTQXKlNzA/ks9/vufe30hrTkph/MfEvM5mYVbfgAn5zZ0v+dJ2wCoe1go= secure: ErqvSFIlL3d9XuMj+T+hO6xZqll8Ubx0DEdHD6NJKi7sH7Be3b3/vUoPdAjdFOP70DhaccbncGCTPZ9hsNKdqYxZmuKx3WWwH4H4U5YdDIViXtH6+B5KdAmvdZIynaj+THQAbVAhr+QyvcqotNySPd3Ac1HCg2YAcUHme6y3FsiRJ79To80JWxTSR1G/oObmeoDn8R18wmH1gHl8KQ7ltC537Osb/H34bJ/hY94hRe8IEmoQE4yz/EP44kGXRb/F87i92y1mO081ZS1I1hs5Kbom43YoItqSVbJP/abPMyCsGDv2FGXaGqk5IVC1k+01pcAjqxCzMvXC272itc0E8OEWqE4qONN+m2S9tyALyOaUZ7j5meWLHQj49Rzo7XIWh1PvvEMovdl/wk/Oc9f0ZywPuvoRht5ZebgXbPWAMMNywwy0GKM4nU0DCyFm23mlzPh4iklo12gEUzq3YLc18RhAZuy4timeevrDCuJMQeQ3sqcQBKCQ+rdOxzVCKKl2sGpNaTJEYaHGT9KLCEGBLmvaB58RKgmGN6IIEwpxSm2SGoirfnQsr+DP+kaSvWPr6R/pZAhO1JzO+azaXvfr+hL2SMX6U7j5+SDmFGIFDwxok7ny1QUTQXKlNzA/ks9/vufe30hrTkph/MfEvM5mYVbfgAn5zZ0v+dJ2wCoe1go=
notifications:
webhooks:
- https://ws.b0n.pl/relaunch

1
Makefile

@ -11,6 +11,7 @@ buildNodeFrontend:
embedFrontend: embedFrontend:
@cd handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.tmpl . @cd handlers/tmpls && esc -o tmpls.go -pkg tmpls -include ^*\.tmpl .
@cd handlers && esc -o static.go -pkg handlers -prefix ../static/build ../static/build @cd handlers && esc -o static.go -pkg handlers -prefix ../static/build ../static/build
bash build/info.sh
getCMDDependencies: getCMDDependencies:
go get -v github.com/mattn/goveralls go get -v github.com/mattn/goveralls

3
README.md

@ -6,6 +6,7 @@
[![Coverage Status](https://coveralls.io/repos/github/maxibanki/golang-url-shortener/badge.svg?branch=master)](https://coveralls.io/github/maxibanki/golang-url-shortener?branch=master) [![Coverage Status](https://coveralls.io/repos/github/maxibanki/golang-url-shortener/badge.svg?branch=master)](https://coveralls.io/github/maxibanki/golang-url-shortener?branch=master)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Download](https://api.bintray.com/packages/maxibanki/golang-url-shortener/travis-ci/images/download.svg?version=0.1) ](https://bintray.com/maxibanki/golang-url-shortener/travis-ci/0.1/link) [![Download](https://api.bintray.com/packages/maxibanki/golang-url-shortener/travis-ci/images/download.svg?version=0.1) ](https://bintray.com/maxibanki/golang-url-shortener/travis-ci/0.1/link)
[![Docker Pulls](https://img.shields.io/docker/pulls/maxibanki/golang_url_shortener.svg)](https://hub.docker.com/r/maxibanki/golang_url_shortener/)
## Main Features ## Main Features
@ -13,7 +14,7 @@
- Visitor Counting - Visitor Counting
- Expirable Links - Expirable Links
- URL deletion - URL deletion
- Authorization System via OAuth 2.0 from Google (more providers following) - Authorization System via OAuth 2.0 (Google, GitHub and Micrsoft)
- High performance database with [bolt](https://github.com/boltdb/bolt) - High performance database with [bolt](https://github.com/boltdb/bolt)
- Easy [ShareX](https://github.com/ShareX/ShareX) integration - Easy [ShareX](https://github.com/ShareX/ShareX) integration
- Dockerizable - Dockerizable

10
build/info.sh

@ -0,0 +1,10 @@
cat > util/info.go <<EOL
package util
var VersionInfo = map[string]string{
"nodeJS": "`node --version`",
"commit": "`git rev-parse HEAD`",
"compilationTime": "`date`",
"yarn": "`yarn --version`",
}
EOL

9
handlers/handlers.go

@ -54,7 +54,7 @@ func (h *Handler) setTemplateFromFS(name string) error {
if err != nil { if err != nil {
return errors.Wrap(err, "could not read token template file") return errors.Wrap(err, "could not read token template file")
} }
templ, err := template.New(name).Funcs(h.engine.FuncMap).Parse(tokenTemplate) templ, err := template.New(name).Parse(tokenTemplate)
if err != nil { if err != nil {
return errors.Wrap(err, "could not create template from file content") return errors.Wrap(err, "could not create template from file content")
} }
@ -74,7 +74,12 @@ func (h *Handler) setHandlers() error {
h.engine.GET("/api/v1/info", h.handleInfo) h.engine.GET("/api/v1/info", h.handleInfo)
h.engine.NoRoute(h.handleAccess, gin.WrapH(http.FileServer(FS(false)))) // Handling the shorted URLs, if no one exists, it checks
// in the filesystem and sets headers for caching
h.engine.NoRoute(h.handleAccess, func(c *gin.Context) {
c.Header("Vary", "Accept-Encoding")
c.Header("Cache-Control", "public, max-age=2592000")
}, gin.WrapH(http.FileServer(FS(false))))
return nil return nil
} }

11
handlers/public.go

@ -3,11 +3,13 @@ package handlers
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"runtime"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/maxibanki/golang-url-shortener/handlers/auth" "github.com/maxibanki/golang-url-shortener/handlers/auth"
"github.com/maxibanki/golang-url-shortener/store" "github.com/maxibanki/golang-url-shortener/store"
"github.com/maxibanki/golang-url-shortener/util"
) )
// urlUtil is used to help in- and outgoing requests for json // urlUtil is used to help in- and outgoing requests for json
@ -93,7 +95,14 @@ func (h *Handler) handleCreate(c *gin.Context) {
} }
func (h *Handler) handleInfo(c *gin.Context) { func (h *Handler) handleInfo(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"providers": h.providers}) info := gin.H{
"providers": h.providers,
"go": runtime.Version(),
}
for k, v := range util.VersionInfo {
info[k] = v
}
c.JSON(http.StatusOK, info)
} }
func (h *Handler) getSchemaAndHost(c *gin.Context) string { func (h *Handler) getSchemaAndHost(c *gin.Context) string {

57
static/src/About/About.js

@ -1,11 +1,64 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Container } from 'semantic-ui-react' import { Container, Table } from 'semantic-ui-react'
export default class AboutComponent extends Component { export default class AboutComponent extends Component {
state = {
info: null
}
componentWillMount() {
fetch("/api/v1/info").then(res => res.json()).then(d => this.setState({ info: d }))
}
render() { render() {
const { info } = this.state
return ( return (
<Container > <Container >
<div>About</div> {info && <Table celled>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Property</Table.HeaderCell>
<Table.HeaderCell>Info</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>Source Code</Table.Cell>
<Table.Cell><a href="https://github.com/maxibanki/golang-url-shortener" target="_blank" rel="noopener noreferrer">github.com/maxibanki/golang-url-shortener</a></Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Author</Table.Cell>
<Table.Cell><a href="https://github.com/maxibanki/" target="_blank" rel="noopener noreferrer">Max Schmitt</a></Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Compilation Time</Table.Cell>
<Table.Cell>{info.compilationTime}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Commit Hash</Table.Cell>
<Table.Cell><a href={"https://github.com/maxibanki/golang-url-shortener/commit/" + info.commit} target="_blank" rel="noopener noreferrer">{info.commit}</a></Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Go Version</Table.Cell>
<Table.Cell>{info.go.replace("go", "")}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>React Version</Table.Cell>
<Table.Cell>{React.version}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Node.js Version</Table.Cell>
<Table.Cell>{info.nodeJS.replace("v", "")}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Yarn Version</Table.Cell>
<Table.Cell>{info.yarn}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>License</Table.Cell>
<Table.Cell><a href="https://github.com/maxibanki/golang-url-shortener/blob/master/LICENSE.md" target="_blank" rel="noopener noreferrer">MIT</a></Table.Cell>
</Table.Row>
</Table.Body>
</Table>}
</Container> </Container>
) )
} }

3
static/src/ShareX/ShareX.css

@ -0,0 +1,3 @@
.token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string {
background: none;
}

2
static/src/ShareX/ShareX.js

@ -6,6 +6,8 @@ import 'prismjs/components/prism-json'
import PrismCode from 'react-prism' import PrismCode from 'react-prism'
import 'prismjs/themes/prism.css'; import 'prismjs/themes/prism.css';
import './ShareX.css'
export default class ShareXComponent extends Component { export default class ShareXComponent extends Component {
state = { state = {
config: JSON.stringify({ config: JSON.stringify({

Loading…
Cancel
Save