Hosword Blog

努力学习


  • 首页

  • 分类

  • 归档

  • 书籍

  • 搜索

GO项目目录下bin,pkg,src从何而来

发表于 2015-10-28 | 分类于 Go

之前有学过一段时间Go语言,前几天忽然发现我的GoPath目录下居然只有src,pkg两个文件夹,那么我的bin文件夹去哪里了呢,仔细看了一下终于发现问题之所在,以下简单介绍一下解决办法。

|– bin 放编译后的可执行文件,可执行文件名字与源代码文件名字一样
|– pkg 放编译后的包文件,包文件名字与所在目录一样,注意:名字与 package 无关
|– src 放源代码文件

GoPath文件结构如下

D:.
├─bin
│ test.exe
│
├─pkg
│ └─windows_amd64
│ mymath.a
│
└─src
├─mymath
│ mymath.go
│
└─test
test.go

src目录

此目录是自己在GoPath目录下手动创建的,用于放源代码文件。

  • 手动在GoPtah目录下添加src目录,如图:
  • 新建两个文件夹mymath,test,分别添加mymath.go,test.go.
    结构如下:
    ├─mymath
    │ mymath.go
    │
    └─test
    test.go
1
2
3
4
5
6
//mymath.go
package math
func Mymath(a int,b int) int {
return a * b
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//test.go
package main
import(
"fmt"
"mymath"
)
func main() {
a := 100
b := 200
fmt.Println(math.Mymath(a,b))
}

pkg目录

此目录是在src的源文件目录下对.go文件通过go install之后自动生成的,放编译后的包文件。由于在尝试过程中我暂时没有发现pkg录出现像bin目录那样不会自动生成的情况,所以这步暂时没有问题。

  • 在src/maymath目录下打开cmder运行go install命令,可以发现 GoPath目录下自动生成了pkg目录。如图

  • 在src/test目录下打开 cmder运行go build命令,可以发现 GoPath目录下并没有自动生成了bin目录,而是在当前目录下生成了test.exe。如图

bin目录

此目录是在src的源文件目录下对 .go文件通过go build和go install之后自动生成的,.go文件要调用pkg下的包文件。那么问题来了,bin目录有时候就不会生成,最后我才发现是环境变量GOBIN的原因。废话不多说直接上图。

  • 查看GO环境变量

  • 找到GOBIN环境变量删除

  • 查看修改后的GO环境变量

  • 删除test/test.exe,在当前目录下打开cmder运行
    go install,查看GoPath目录结构即可发现bin已自动生成,如图:

Go环境变量配置

  • GOROOT:Go的安装目录
  • GOPATH:用于存放Go语言Package的目录,这个目录不能在Go的安装目录中
  • GOBIN:Go二进制文件存放目录,写成%GOROOT%\bin就好
  • GOOS:操作系统
  • GOARCH:指定系统环境,i386表示x86,amd64表示x64
  • PATH:需要将%GOBIN%加在PATH变量的最后,方便在命令行下运行Go
  • 其他GO环境变量可以用cmd命令查询

更多资料

Golang项目目录结构组织
GO环境配置

注:以上提到的cmder是一个cmd工具,详细请查看前面的文章

windows删除文件报错The source filename are larger than is supported by the file system

发表于 2015-10-26 | 分类于 Windows

Error:The source filename are larger than is supported by the file system···

解决方法:

you want to delete a tree D:\very\long\path, you don’t necessarily need to use any tools such as Robocopy.

  • Go to the root directory of the drive which contains the directory which you can’t delete
  • Create a directory with a single letter name, eg D:\a,Navigate to inside the directory that you want to delete, in this caseD:\very\long\path
  • Select all (Ctrl+A) and Cut (Ctrl-X)
  • Navigate to the folder you just createdPaste (Ctrl-V)
  • now, move up to the root directory and delete the temp folder, in this caseD:\a
  • Then go back and delete the original directory

GitHub Pages与Hexo搭建一个独立博客(二)

发表于 2015-10-15 | 分类于 教程

刚刚使用了一下hexo,并用hexo搭建了自己的博客,感觉到了hexo的强大之处。

快捷方便 容易上手,网上有很好的博客教程

注册GitHub账户

进入gitHub官网

https://github.com/

注册帐号

(按步骤进行)

登录GitHub

关于GitHub如何使用请自行科普。
如何高效利用GitHub

配置和使用Github

以下教程主要参考如何搭建一个独立博客——简明Github Pages与Hexo教程写成。

配置SSH keys

我们如何让本地git项目与远程的github建立联系呢?用SSH keys

检查SSH keys的设置

首先我们需要检查你电脑上现有的ssh key

1
cd ~/. ssh 检查本机的ssh密钥

如果提示:No such file or directory 说明你是第一次使用git。

生成新的SSH Key:

1
ssh-keygen -t rsa -C "邮件地址@youremail.com"

一直回车。。。

注意: 此处的邮箱地址,你可以输入自己的邮箱地址;注意2: 此处的「-C」的是大写的「C」
最后看到这样的界面,就成功设置ssh key了:

添加SSH Key到GitHub

在本机设置SSH Key之后,需要添加到 GitHub上,以完成SSH链接的设置。

1.打开本地C:\Users\用户名\.ssh\id_rsa.pub文件,用文本方式打开不建议用windows自带的文本编辑器。此文件里面内容为刚才生成的密钥。如果看不到这个文件,你需要设置显示隐藏文件。准确的复制这个文件的内容,才能保证设置的成功。

2.登陆GitHub系统。点击右上角的Account Settings--->SSH Public keys ---> add another public keys

3.把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了

测试

可以输入下面的命令,看看设置是否成功,git@github.com的部分不要修改:

1
ssh -T git@github.com

如果是下面的反馈:

1
2
3
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?

不要紧张,输入yes就好,然后会看到:

1
Hi cnfeat! You've successfully authenticated, but GitHub does not provide shell access.

设置用户信息

现在你已经可以通过SSH链接到GitHub了,还有一些个人信息需要完善的。

Git会根据用户的名字和邮箱来记录提交。GitHub也是用这些信息来做权限的处理,输入下面的代码进行个人信息的设置,把名称和邮箱替换成你自己的,名字必须是你的真名,而不是GitHub的昵称。

1
2
git config --global user.name "08hjz"//用户名
git config --global user.email "08hjz@gmail.com"//填写自己的注册邮箱

SSH Key配置成功

本机已成功连接到GitHub
常见错误请参考:
[1] Generating SSH keys
[2] Error: Permission denied (publickey)

建立仓库

自定义用户名

登录GitHub,注册自定义用户名如08hjz

创建New repository

在主页右下角创建New repository,name必须和用户名一致如08hjz.github.io
首次创建耐心等待10分钟左右审核,之后即可访问静态主页如http://08hjz.github.io

hexo使用

hexo主题

查看主题

[1] 有那些好看的hexo主题?
[2] Themes
[3] hexoThemes

克隆主题到本地


复制ssh,切换到本地博客文件hexo\themes目录下,克隆主题如图

1
git clone git@github.com:reee/hexo-theme-flat.git

hexo配置

Hexo官方文档-配置

修改站点配置文件:hexo/_config.yml

我的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: xxx Blog #博客名
subtitle: xxxxx #小标题
description: xxxxxx #描述
author: xxxx #作者
language: zh-CN #语言
#timezone: "UTC+08:00" #时区
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: true
tab_replace:
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD #日期格式
time_format: HH:mm:ss #时间格式
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10 #每页显示多少文章
pagination_dir: page
# Extensions
## Plugins: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/
theme: hexo-theme-next #自定义题
swiftype_key: "xxxxxx" #swiftype搜索服务
baidu_analytics: xxxxxxxx #百度统计
#duoshuo
duoshuo_shortname: xxx #多说评论
# JiaThis 分享服务
#jiathis: true
# 多说分享服务
duoshuo_share: true
since: 2015
###这个deploy配置比较重要提交到github全靠它,切记一定要配置这个
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/yourname/yourname.github.io.git #用自己的用户名
branch: master
#touxiang
avatar: /images/avatar.png #头像
# Social links
social: #其他链接自定义
github: xxxxx
weibo: xxxxx
douban: xxxxxxx
zhihu: xxxxxx
# 等等
# title, chinese available
links_title: Links
# links
links: #链接
MacTalk: http://theme-next.iissnan.com/

网站

参数 描述
title 网站标题
subtitle 网站副标题
description 网站描述
author 您的名字
language 网站使用的语言
timezone 网站时区。Hexo 预设使用您电脑的时区。

网址

参数 描述 默认值
url 网址
root 网站根目录
permalink_default 永久链接中各部分的默认值
permalink 文章的永久链接 格式 :year/:month/:day/:title/

网站存放在子目录
如果您的网站存放在子目录中,例如 http://yoursite.com/blog,则请将您的url设为 http://yoursite.com/blog并把root设为/ blog/。

目录

参数 描述 默认值
source_dir 资源文件夹,这个文件夹用来存放内容。 source
public_dir 公共文件夹,这个文件夹用于存放生成的站点文件。 public
tag_dir 标签文件夹 tags
archive_dir 归档文件夹 archives
category_dir 分类文件夹 categories
code_dir Include code 文件夹 downloads/code
skip_render 跳过指定文件的渲染,您可使用 glob 来配置路径。
i18n_dir 国际化(i18n)文件夹 :lang

文章

参数 描述 默认值
new_post_name 新文章的文件名称 :title.md
default_layout 预设布局 post
auto_spacing 在中文和英文之间加入空格 false
titlecase 把标题转换为 title case false
external_link 在新标签中打开链接 true
filename_case 把文件名称转换为 (1) 小写或 (2) 大写 0
render_drafts 显示草稿 false
post_asset_folder 启动 Asset 文件夹 false
relative_link 把链接改为与根目录的相对位址 false
highlight 代码块的设置
future 显示未来的文章 true

分类 & 标签

参数 描述 默认值
category_map 分类别名
tag_map 标签别名
default_category 默认分类 uncategorized

日期时间格式

Hexo 使用 Moment.js 来解析和显示时间

参数 描述 默认值
date_format 日期格式 MMM D YYYY
time_format 时间格式 H:mm:ss

分页

参数 描述 默认值
per_page 每页显示的文章量 (0 = 关闭分页功能) 10
pagination_dir 分页目录 page

扩展

参数 描述
theme 当前主题名称
deploy 部署

特别注意:如:duoshuo_shortname: xxx #多说评论,duoshuo_shortname:和xxx中间是有一个空格的,修改的时候请认真检查此处最容易出错。

主题配置文件

修改站点配置文件:hexo/themes/你的主题/_config.yml,请根据自己的喜好修改。
我的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# when running hexo in a subdirectory (e.g. domain.tld/blog), remove leading slashes ( "/archives" -> "archives" )
menu:
home: /
categories: /categories #10.14
archives: /archives
tags: /tags
books: /books
#commonweal: /404.html
tools: /tools #10.14
about: /about #10.14
# Place your favicon.ico to /source directory.
favicon: /favicon.ico
# Set default keywords (Use a comma to separate)
keywords: "Hexo,next"
# Set rss to false to disable feed link.
# Leave rss as empty to use site's feed link.
# Set rss to specific value if you have burned your feed already.
rss:
# Icon fonts
# Place your font into next/source/fonts, specify directory-name and font-name here
# Avialable: default | linecons | fifty-shades | feather
icon_font: default
#icon_font: fifty-shades
#icon_font: feather
#icon_font: linecons
#icon_font: icomoon
# Code Highlight theme
# Available value: normal | night | night eighties | night blue | night bright
# https://github.com/chriskempson/tomorrow-theme
highlight_theme: night eighties
# MathJax Support
mathjax: true
# Schemes
scheme: Mist
# Sidebar, available value:
# - post expand on posts automatically. Default.
# - always expand for all pages automatically
# - hide expand only when click on the sidebar toggle icon.
sidebar: post
#sidebar: always
#sidebar: hide
# Automatically scroll page to section which is under <!-- more --> mark.
scroll_to_more: true
# Automatically add list number to toc.
toc_list_number: true
# Automatically Excerpt
auto_excerpt:
enable: false
length: 150
# Use Lato font
# Note: this option is avialable only when the language is not `zh-Hans`
use_font_lato: true
# Make duoshuo show UA
# user_id must NOT be null when admin_enable is true!
# you can visit http://dev.duoshuo.com get duoshuo user id.
duoshuo_info:
ua_enable: true
admin_enable: false
user_id: 0
duoshuo_hotartical: true
#admin_nickname: ROOT
## DO NOT EDIT THE FOLLOWING SETTINGS
## UNLESS YOU KNOW WHAT YOU ARE DOING
# Use velocity to animate everything.
use_motion: true
# Fancybox
fancybox: true
# Static files
vendors: vendors
css: css
js: js
images: images
# Theme version
version: 0.4.5.1
# JiaThis 分享服务
#jiathis: true
# 多说分享服务
duoshuo_share: true

导航栏添加自定义页面

1.命令手动生成自定义页面hexo n page "about"
2.编辑hexo/source/about/index.md内容
3.修改themes/jacman/_config.yml文件

1
2
menu:
关于: /about

发表文章

  1. hexo new "my new post"
  2. 在hexo\source\_posts中打开这个文件(打开方式用“记事本”即可),配置开头再写文章。
    1
    2
    3
    4
    5
    6
    title: my new post #可以改成中文的,如“新文章”
    date: 2015-10-29 17:56:29 #发表日期,一般不改动
    categories: blog #文章文类
    tags: [博客,文章] #文章标签,多于一项时用这种格式
    ---
    #这里是正文,用markdown写,使用方法参照我原来的博客[Introduction to markdown](http://zipperary.com/2013/05/22/introduction-to-markdown/)

3.hexo clean清除文件之后再hexo g #hexo generate生成文件。
4.hexo s #hexo server,访问localhost:4000(也可以用127.0.0.1)预览效果,退出server用Ctrl+c.
5.hexo d #hexo deploy同步到github,期间可能需要输入用户名和密码,访问网站看看效果。

注意:以后每次发表文章就是按照这个1-5的步骤。


参考资料:
[1] hexo你的博客
[2] 如何搭建一个独立博客——简明Github Pages与Hexo教程

GitHub Pages与Hexo搭建一个独立博客(一)

发表于 2015-10-11 | 分类于 教程

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。 Hexo 是一个基于 Node.js 的静态博客程序, 可以方便的生成静态网页托管在 github 和 Heroku 上。

为什么要用静态博客?

1.跨平台同步文件
2.系统简单易懂, 毫不臃肿, 方便改版
3.众多第三方应用, 容易做自定义功能扩展
4.纯静态, 极低的服务器压力
5.最重要使用 Markdown 标记语法, 迁移什么的都非常方便
6.能够托管在 Github 上

环境配置

什么是环境变量?
为什么要配置环境变量呢?
简单的说吧,就比如说你要写篇日记那么问题是你首先得准备好一个笔记本一样。更深层次请自行谷歌或度娘科普。
环境变量

安装Git服务

关于Git服务,推荐两个不错的教程

  • Git教程- 廖雪峰的官方网站
  • git - 简明指南

Windows:下载并安装git

推荐使用cmder,因为cmderer自带了msysgit使用更加方便.

  • cmder官网下载地址
  • cmder百度云下载地址 访问密码: qfdi
  • 添加右键cmder cmder简单介绍及配置
    检查git版本
    打开cmder运行
    1
    git

安装node.js

Windows下的Node.js 安装配置

下载node.js安装包

node.js官网
node.js下载地址

安装(最新安装包默认配置好path变量,无需自行配置)

安装步骤:

步骤 1 : 双击下载后的安装包 node-v4.1.2-x64.msi,如下所示:

步骤 2 : 点击以上的Run(运行),将出现如下界面:

步骤 3 : 勾选接受协议选项,点击 next(下一步) 按钮 :

步骤 4 : Node.js默认安装目录为 “C:\Program Files\nodejs\” , 你可以修改目录,并点击 next(下一步)

步骤 5 : 点击树形图标来选择你需要的安装模式 , 然后点击下一步 next(下一步)

步骤 6 :点击 Install(安装) 开始安装Node.js。你也可以点击 Back(返回)来修改先前的配置。 然后并点击 next(下一步):

安装过程:

点击 Finish(完成)按钮退出安装向导。

检查版本

打开cmder运行

1
node -v

安装hexo

Hexo

打开cmder运行

1
npm install -g hexo-cli

检查版本

打开cmder运行

1
hexo -v

安装Hexo插件

1
2
3
4
5
6
7
8
9
10
11
12
13
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-server --save
npm install hexo-deployer-git --save
npm install hexo-deployer-heroku --save
npm install hexo-deployer-rsync --save
npm install hexo-deployer-openshift --save
npm install hexo-renderer-marked@0.2 --save
npm install hexo-renderer-stylus@0.2 --save
npm install hexo-generator-feed@1 --save
npm install hexo-generator-sitemap@1 --save

Hexo建站

安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件,如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。

1
2
hexo init <folder>
npm install

新建完成后,指定文件夹的目录如下:

1
2
3
4
5
6
7
8
9
.
├── _config.yml
├── package.json
├── scaffolds
├── scripts
├── source
| ├── _drafts
| └── _posts
└── themes

  • _config.yml
    网站的 配置 信息,您可以在此配置大部分的参数。

  • package.json
    应用程序的信息。EJS, Stylus 和 Markdown renderer 已默认安装,您可以自由移除。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package.json
    {
    "name": "hexo-site",
    "version": "",
    "private": true,
    "hexo": {
    "version": ""
    },
    "dependencies": {
    "hexo-renderer-ejs": "*",
    "hexo-renderer-stylus": "*",
    "hexo-renderer-marked": "*"
    }
    }
  • scaffolds
    模版 文件夹。当您新建文章时,Hexo 会根据 scaffold 来建立文件。

  • scripts
    脚本 文件夹。脚本是扩展 Hexo 最简易的方式,在此文件夹内的 JavaScript 文件会被自动执行。

  • source
    资源文件夹是存放用户资源的地方。除 posts 文件夹之外,开头命名为 (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。

  • themes
    主题 文件夹。Hexo 会根据主题来生成静态页面。

    配置

    参见hexo配置
    您可以在 _config.yml 中修改大部份的配置。

    常用命令

  • init
    1
    hexo init [folder]

新建一个网站。如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。

  • new
    1
    hexo new [layout] <title>

新建一篇文章。如果没有设置 layout 的话,默认使用 _config.yml 中的 default_layout 参数代替。如果标题包含空格的话,请使用引号括起来。

  • generate
    1
    2
    hexo generate
    hexo g #缩写

生成静态文件。

选项 描述
-d, --deploy 文件生成后立即部署网站
-w, --watch 监视文件变动
  • server
    1
    2
    hexo server
    hexo s #缩写

启动服务器。

选项 描述
-p, --port 重设端口
-s,--static 只使用静态文件
-l, --log 启动日记记录,或覆盖记录格式
  • deploy
    1
    hexo deploy

部署网站。

参数 描述
-g, --generate 部署网站前,需要预先生成静态文件
  • clean
    1
    hexo clean

清除缓存文件 (db.json) 和已生成的静态文件 (public)。

本地运行

  • 新建目录...\Hexo--test
  • 在当前目录下打开cmder,运行hexo init

    返回当前目录查看文件目录,如下:

  • 在cmder运行hexo g

    返回当前目录查看文件目录,如下(public目录为hexo g生成):

  • 在cmder运行hexo s

  • 打开浏览器输入127.0.0.1:4000

  • 至此本地文件建立完成

为什么要搭建一个博客呢?

发表于 2015-10-11 | 分类于 随笔
  • 生活中有好多为什么,有时候我们并不深究只是按照万物发展的自然规律顺其自然,可是细细想来,似乎都有不言而喻的理由与借口,既然如此,何必深究···

过去的时间到底有多少?

不知道什么时候开始害怕长大···
我只知道小时候盼望着长大···
即使已经是过去的时间,过去的人,过去的事,过去的一切,都仿佛在昨天。生活既不是用来怀旧的,也不是用来填充时间和空间的空白的。那么我们的时间都去哪了?你可曾记得过去的时间到底有多少。

你真正利用过的时间都在做有意义的事吗?

有意义的事?
我认为有意义的事是什么?
的确,从很小的时候开始我们已经对时间有了一个明确的认识,以致于到今日我们也不肯承认自己对时间的忽视。过去的每一天也许你一直在努力,也许你只努力过几天,也许你从来都没有努力,可是就在刚才你已经意识到自己该做应该做的事了。如此说来,在过去的时间里每个人都是幸运的,至少我们都有所收获。

那么你浪费的时间都去哪了?

我们是在浪费时间中寻找利用时间的借口,而且我们也不是黑夜里的独行者。

你学到了那些知识?

理论知识,人生哲理,心灵鸡汤,做人,做事···

你觉得你学到的那些知识可以使你收益终生?

我学会吃饭,So我就不会饿死。

More info: 你觉得受益终生的技能是?

Hosword

Hosword

学会学习,学习做人,学习做事。

5 日志
4 分类
8 标签
RSS
github weibo douban zhihu
Links
  • ZFLiu
© 2015 - 2017 Hosword
由 Hexo 强力驱动
主题 - NexT.Pisces