github.com/rixingyike/ginblog

一个基于gin框架开发的golang博客系统,我将基于它开发日课产品


Install
go get github.com/rixingyike/ginblog

Documentation

GIN-powered blog boilerplate

Provides essentials that most web blogs need - MVC pattern, user authorisation, SQL db migration, admin dashboard, javascript form validation, rss feeds, etc.

It consists of the following core components:

TODO (May be)

Screenshots

Home page

Dashboard

Markdown editor

Fancy 404, 405, 500 error pages

Usage

git clone https://github.com/denisbakhtin/ginblog.git
cd ginblog
go get .

Copy sample config cp config/config.json.example config/config.json, create postgresql database, modify config/config.json accordingly.

Type go run main.go -migrate=up to create users and pages tables.

go run main.go to launch web server.

Deployment

make build

Upload ginblog binary and public directory to your server. If you find rice embed-go is running slow on your system, consider using other go.rice packing options with go generate command.

Project structure

/config

Contains application configuration file.

/controllers

All your controllers that serve defined routes.

/helpers

Helper functions.

/migrations

Database schema migrations

/models

You database models.

/public

It has all your static files

/system

Core functions and structs.

/views

Your views using standard Go template system.

main.go

This file starts your web application, contains routes definition & some custom middlewares.

Make it your own

I assume you have followed installation instructions and you have ginblog installed in your GOPATH location.

Let's say I want to create Amazing Website. I create new GitHub repository https://github.com/denisbakhtin/amazingblog (of course replace that with your own repository).

Now I have to prepare ginblog. First thing is that I have to delete its .git directory.

I issue:

rm -rf src/github.com/denisbakhtin/ginblog/.git

Then I want to replace all references from github.com/denisbakhtin/amazingblog to github.com/denisbakhtin/amazingblog:

grep -rl 'github.com/denisbakhtin/ginblog' ./ | xargs sed -i 's/github.com\/denisbakhtin\/ginblog/github.com\/denisbakhtin\/amazingblog/g'

Now I have to move all ginblog files to the new location:

mv src/github.com/denisbakhtin/ginblog/ src/github.com/denisbakhtin/amazingblog

And push it to my new repository at GitHub:

cd src/github.com/denisbakhtin/amazingblog
git init
git add --all .
git commit -m "Amazing Blog First Commit"
git remote add origin https://github.com/denisbakhtin/amazingblog.git
git push -u origin master

You can now go back to your GOPATH and check if everything is ok:

go install github.com/denisbakhtin/amazingblog

And that's it.

Continuous Development

For Continuous Development I recommend using Reflex - https://github.com/cespare/reflex

You can install Reflex by issuing:

go get github.com/cespare/reflex

Then create a config file reflex.conf in your GOPATH:

# Restart server when .go, .html files change
-sr '(\.go|\.html)$' go run main.go

Now if you run reflex -c reflex.conf, project will automatically rebuild itself when a change to *.go, *.html file occurs. For more options read https://github.com/cespare/reflex#usage