Skip to content

Commit

Permalink
首次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
shiguanghuxian committed Dec 25, 2018
0 parents commit 15f1db1
Show file tree
Hide file tree
Showing 967 changed files with 450,821 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

e3w
default.etcd
etcd-manage

bin/etcd-manage
bin/logs/*

tpls/dist/*
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.11 as backend
RUN mkdir -p /go/src/github.com/shiguanghuxian/etcd-manage
ADD . /go/src/github.com/shiguanghuxian/etcd-manage
WORKDIR /go/src/github.com/shiguanghuxian/etcd-manage
RUN CGO_ENABLED=0 go build

# FROM node:8 as frontend
# RUN mkdir /app
# ADD static /app
# WORKDIR /app
# RUN npm install -g cnpm --registry=https://registry.npm.taobao.org
# RUN cnpm install -g @vue/cli
# RUN cnpm install && npm run build

FROM alpine:latest
RUN mkdir -p /app/static/dist /app/conf
COPY --from=backend /go/src/github.com/shiguanghuxian/etcd-manage/etcd-manage /app
# COPY --from=frontend /app/dist /app/static/dist
COPY static/dist /app/static/dist
COPY conf/config.default.ini /app/conf
EXPOSE 9090
WORKDIR /app
CMD ["./etcd-manage"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 时光弧线

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
default:
@echo 'Usage of make: [ build | linux_build | windows_build | clean ]'

build:
@go build -ldflags "-X main.VERSION=1.0.0 -X main.GIT_HASH=`git rev-parse HEAD` -s" -o ./bin/etcd-manage ./

linux_build:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.VERSION=1.0.0 -X main.GIT_HASH=`git rev-parse HEAD` -s" -o ./bin/etcd-manage ./

windows_build:
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.VERSION=1.0.0 -X main.GIT_HASH=`git rev-parse HEAD` -s" -o ./bin/etcd-manage.exe ./

run: build
@./bin/etcd-manage

install: build
@mv ./bin/etcd-manage $(GOPATH)/bin/etcd-manage

build_web:
cd static && npm run build && cp -r dist ../tpls && cd ../tpls && ./compile.sh

clean:
@rm -f ./bin/etcd-manage*

.PHONY: default build linux_build windows_build clean
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# etcd-manage

本项目是 [e3w](https://github.com/soyking/e3w) 的一个副本,修改了里边etcd库(etcd原来饮用地址不可以)的引入地址,和加了允许跨域请求。

可以使用我编写的docker-compose,快速在docker中启动etcd3管理界面 地址: [https://github.com/shiguanghuxian/docker-compose/tree/master/etcd33](https://github.com/shiguanghuxian/docker-compose/tree/master/etcd33)

## 编译和运行

由于前端使用了vue-cli3,在docker中没有成功编译前端代码,所以需要手动编译前端代码。


***前端代码编译:***

>
> 1. 安装node
>
> 下载地址 [https://nodejs.org/](https://nodejs.org/)
>
> 2. 安装cnpm加速node依赖安装速度
>
> npm install -g cnpm --registry=https://registry.npm.taobao.org
>
> 3. 安装vue-cli3
>
> cnpm install -g @vue/cli
>
> 4. 安装依赖,编译项目
>
> cd $GOPATH/github.com/shiguanghuxian/etcd-manage/static
>
> cnpm install && npm run build
>
***运行***

项目中用到的go.etcd.io/etcd库,可以从github下载[https://github.com/etcd-io/etcd](https://github.com/etcd-io/etcd),拷贝到对应目录

> 1. 安装go依赖
>
> govendor add +external
>
> 2. 运行
> docker-compose up
>
## 运行效果
首页
![](./images/abc.png)

列表形式显示
![](./images/list.png)

添加
![](./images/add.png)

删除
![](./images/del.png)

查看&修改
![](./images/show.png)
45 changes: 45 additions & 0 deletions bin/config/cfg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# debug模式
debug = true
# 日志文件路径
log_path = ""

# http 监听端口
[http]
# 监听地址
address = "127.0.0.1"
# 监听端口
port = 10280

## 一下每一个server为一个etcd服务 ##
[[server]]
# 显示名称
title = "QA测试环境"
# 标识名
name = "qa"
# etcd连接地址 如果为集群请填写全部地址
address = ["127.0.0.1:2379"]
# 查看的key前缀
key_prefix = "root"
# 简述信息
desc = "qa环境etcd"
# 可访问服务器角色列表 - 不写则为所有用户可访问
roles = ["admin"]

[[server]]
title = "本机"
name = "local"
address = ["127.0.0.1:2379"]
key_prefix = "root"
desc = "本机环境"
roles = ["admin","dev"]

## 以下为用户列表 ##
[[user]]
username = "admin"
password = "123456"
role = "admin"

[[user]]
username = "dev_user"
password = "123456"
role = "dev"
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'

services:
etcd:
image: "quay.io/coreos/etcd:v3.3"
container_name: "etcdv3.3"
environment:
ETCD_ADVERTISE_CLIENT_URLS: "http://0.0.0.0:2379"
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
ETCDCTL_API: "3"
volumes:
- ./default.etcd:/default.etcd
ports:
- 2379:2379
- 2380:2380
- 4001:4001
etcd-manage:
build: .
volumes:
- ./conf/config.default.ini:/app/conf/config.default.ini
ports:
- "9090:9090"
depends_on:
- etcd
Binary file added images/abc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/del.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/forkme_green_007200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/show.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"log"
"os"
"os/signal"
"syscall"

"github.com/shiguanghuxian/etcd-manage/program"
)

func main() {
// 系统日志显示文件和行号
log.SetFlags(log.Lshortfile | log.LstdFlags)

// 服务对象
p, err := program.New()
if err != nil {
log.Println(err)
os.Exit(1)
}
err = p.Run()
if err != nil {
log.Println(err)
os.Exit(1)
}

// 监听退出信号
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGUSR1, syscall.SIGUSR2)
<-c
p.Stop()
log.Println("程序退出")
}
31 changes: 31 additions & 0 deletions program/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package common

import (
"fmt"
"os"
"path/filepath"
)

// GetRootDir 获取执行路径
func GetRootDir() string {
// 文件不存在获取执行路径
file, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
file = fmt.Sprintf(".%s", string(os.PathSeparator))
} else {
file = fmt.Sprintf("%s%s", file, string(os.PathSeparator))
}
return file
}

// PathExists 判断文件或目录是否存在
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
100 changes: 100 additions & 0 deletions program/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package config

import (
"os"

"github.com/naoina/toml"
"github.com/shiguanghuxian/etcd-manage/program/common"
)

// Config 配置
type Config struct {
Debug bool `toml:"debug"`
LogPath string `toml:"log_path"`
HTTP *HTTP `toml:"http"`
Server []*EtcdServer `toml:"server"`
Users []*User `toml:"user"`
}

// GetUserByUsername 根据用户名获取用户信息
func (c *Config) GetUserByUsername(username string) *User {
if c.Users != nil && len(c.Users) > 0 {
for _, u := range c.Users {
if u.Username == username {
return u
}
}
}
return nil
}

// HTTP http 件套配置
type HTTP struct {
Address string `toml:"address"`
Port int `toml:"port"`
}

// EtcdServer etcd 服务
type EtcdServer struct {
Title string `toml:"title"`
Name string `toml:"name"`
Address []string `toml:"address"`
KeyPrefix string `toml:"key_prefix"`
Desc string `toml:"desc"`
Roles []string `toml:"roles"` // 可访问此etcd服务的角色列表
}

// User 用户
type User struct {
Username string `toml:"username"`
Password string `toml:"password"`
Role string `toml:"role"`
}

// GetEtcdServer 根据服务标识查找服务
func GetEtcdServer(name string) *EtcdServer {
if cfg == nil {
return nil
}
for _, v := range cfg.Server {
if v.Name == name {
return v
}
}
return nil
}

var (
cfg *Config
)

// GetCfg 获取配置
func GetCfg() *Config {
if cfg == nil {
LoadConfig("")
}
return cfg
}

// LoadConfig 读取配置
func LoadConfig(cfgPath string) (*Config, error) {
cfgPath = getCfgPath(cfgPath)
f, err := os.Open(cfgPath)
if err != nil {
return nil, err
}
defer f.Close()
cfg = new(Config)
if err := toml.NewDecoder(f).Decode(cfg); err != nil {
return nil, err
}

return cfg, nil
}

func getCfgPath(cfgPath string) string {
if cfgPath == "" {
cfgPath = common.GetRootDir() + "config/cfg.toml"
}
return cfgPath
}
Loading

0 comments on commit 15f1db1

Please sign in to comment.