From 1ec0ee35b61e14db14040ebee64c9d92a18c4862 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 20 Sep 2021 20:33:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 323 ++++++++++++++++++ pkg/middle/data.go | 24 ++ pkg/middle/middle.go | 62 ++++ pkg/middle/middle_test.go | 7 + pkg/middle/send.go | 24 ++ pkg/middle/storage.go | 24 ++ pkg/middle/upload.go | 25 ++ ...04\347\220\206\346\226\271\346\241\210.md" | 3 + source | 0 9 files changed, 492 insertions(+) create mode 100755 install.sh create mode 100644 pkg/middle/data.go create mode 100644 pkg/middle/middle.go create mode 100644 pkg/middle/middle_test.go create mode 100644 pkg/middle/send.go create mode 100644 pkg/middle/storage.go create mode 100644 pkg/middle/upload.go create mode 100644 "pkg/middle/\344\270\255\351\227\264\344\273\266\345\244\204\347\220\206\346\226\271\346\241\210.md" create mode 100644 source diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..f52c9d8 --- /dev/null +++ b/install.sh @@ -0,0 +1,323 @@ +#!/bin/sh +# +# This script should be run via curl: +# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +# or via wget: +# sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +# or via fetch: +# sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +# +# As an alternative, you can first download the install script and run it afterwards: +# wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh +# sh install.sh +# +# You can tweak the install behavior by setting variables when running the script. For +# example, to change the path to the Oh My Zsh repository: +# ZSH=~/.zsh sh install.sh +# +# Respects the following environment variables: +# ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh) +# REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh) +# REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS) +# BRANCH - branch to check out immediately after install (default: master) +# +# Other options: +# CHSH - 'no' means the installer will not change the default shell (default: yes) +# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) +# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) +# +# You can also pass some arguments to the install script to set some these options: +# --skip-chsh: has the same behavior as setting CHSH to 'no' +# --unattended: sets both CHSH and RUNZSH to 'no' +# --keep-zshrc: sets KEEP_ZSHRC to 'yes' +# For example: +# sh install.sh --unattended +# or: +# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended +# +set -e + +# Track if $ZSH was provided +custom_zsh=${ZSH:+yes} + +# Default settings +ZSH=${ZSH:-~/.oh-my-zsh} +REPO=${REPO:-mirrors/oh-my-zsh} +REMOTE=${REMOTE:-https://gitee.com/${REPO}.git} +BRANCH=${BRANCH:-master} + +# Other options +CHSH=${CHSH:-yes} +RUNZSH=${RUNZSH:-yes} +KEEP_ZSHRC=${KEEP_ZSHRC:-no} + + +command_exists() { + command -v "$@" >/dev/null 2>&1 +} + +fmt_error() { + printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2 +} + +fmt_underline() { + printf '\033[4m%s\033[24m\n' "$*" +} + +fmt_code() { + # shellcheck disable=SC2016 # backtic in single-quote + printf '`\033[38;5;247m%s%s`\n' "$*" "$RESET" +} + +setup_color() { + # Only use colors if connected to a terminal + if [ -t 1 ]; then + RED=$(printf '\033[31m') + GREEN=$(printf '\033[32m') + YELLOW=$(printf '\033[33m') + BLUE=$(printf '\033[34m') + BOLD=$(printf '\033[1m') + RESET=$(printf '\033[m') + else + RED="" + GREEN="" + YELLOW="" + BLUE="" + BOLD="" + RESET="" + fi +} + +setup_ohmyzsh() { + # Prevent the cloned repository from having insecure permissions. Failing to do + # so causes compinit() calls to fail with "command not found: compdef" errors + # for users with insecure umasks (e.g., "002", allowing group writability). Note + # that this will be ignored under Cygwin by default, as Windows ACLs take + # precedence over umasks except for filesystems mounted with option "noacl". + umask g-w,o-w + + echo "${BLUE}Cloning Oh My Zsh...${RESET}" + + command_exists git || { + fmt_error "git is not installed" + exit 1 + } + + ostype=$(uname) + if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -q msysgit; then + fmt_error "Windows/MSYS Git is not supported on Cygwin" + fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH" + exit 1 + fi + + git clone -c core.eol=lf -c core.autocrlf=false \ + -c fsck.zeroPaddedFilemode=ignore \ + -c fetch.fsck.zeroPaddedFilemode=ignore \ + -c receive.fsck.zeroPaddedFilemode=ignore \ + --depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || { + fmt_error "git clone of oh-my-zsh repo failed" + exit 1 + } + + echo +} + +setup_zshrc() { + # Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones + # with datestamp of installation that moved them aside, so we never actually + # destroy a user's original zshrc + echo "${BLUE}Looking for an existing zsh config...${RESET}" + + # Must use this exact name so uninstall.sh can find it + OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh + if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then + # Skip this if the user doesn't want to replace an existing .zshrc + if [ "$KEEP_ZSHRC" = yes ]; then + echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}" + return + fi + if [ -e "$OLD_ZSHRC" ]; then + OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)" + if [ -e "$OLD_OLD_ZSHRC" ]; then + fmt_error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}" + fmt_error "re-run the installer again in a couple of seconds" + exit 1 + fi + mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}" + + echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \ + "${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}" + fi + echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}" + mv ~/.zshrc "$OLD_ZSHRC" + fi + + echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}" + + sed "/^export ZSH=/ c\\ +export ZSH=\"$ZSH\" +" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp + mv -f ~/.zshrc-omztemp ~/.zshrc + + echo +} + +setup_shell() { + # Skip setup if the user wants or stdin is closed (not running interactively). + if [ "$CHSH" = no ]; then + return + fi + + # If this user's login shell is already "zsh", do not attempt to switch. + if [ "$(basename -- "$SHELL")" = "zsh" ]; then + return + fi + + # If this platform doesn't provide a "chsh" command, bail out. + if ! command_exists chsh; then + cat < ~/.shell.pre-oh-my-zsh + else + grep "^$USERNAME:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh + fi + + # Actually change the default shell to zsh + if ! chsh -s "$zsh"; then + fmt_error "chsh command unsuccessful. Change your default shell manually." + else + export SHELL="$zsh" + echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}" + fi + + echo +} + +main() { + # Run as unattended if stdin is not a tty + if [ ! -t 0 ]; then + RUNZSH=no + CHSH=no + fi + + # Parse arguments + while [ $# -gt 0 ]; do + case $1 in + --unattended) RUNZSH=no; CHSH=no ;; + --skip-chsh) CHSH=no ;; + --keep-zshrc) KEEP_ZSHRC=yes ;; + esac + shift + done + + setup_color + + if ! command_exists zsh; then + echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first." + exit 1 + fi + + if [ -d "$ZSH" ]; then + echo "${YELLOW}The \$ZSH folder already exists ($ZSH).${RESET}" + if [ "$custom_zsh" = yes ]; then + cat < Date: Tue, 21 Sep 2021 12:19:17 +0800 Subject: [PATCH 2/4] doc(midlle): add middle driver doc --- pkg/middle/driver.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 pkg/middle/driver.go diff --git a/pkg/middle/driver.go b/pkg/middle/driver.go new file mode 100644 index 0000000..2ea8b57 --- /dev/null +++ b/pkg/middle/driver.go @@ -0,0 +1,15 @@ +package middle + +type eventQueueApi interface { + Put(key string, val interface{}) + Get(key string) interface{} + Start() +} + +type driver struct { + conf []*MiddlewareConf +} + +func Newdriver() *driver { + return new(driver) +} -- Gitee From 4b02b82b647091fff579b5ccba6e7b1d9f9dd192 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Tue, 21 Sep 2021 14:31:32 +0800 Subject: [PATCH 3/4] "test(middle):driver doc" --- pkg/middle/driver_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 pkg/middle/driver_test.go diff --git a/pkg/middle/driver_test.go b/pkg/middle/driver_test.go new file mode 100644 index 0000000..19fd065 --- /dev/null +++ b/pkg/middle/driver_test.go @@ -0,0 +1,12 @@ +package middle + +import "testing" + +func TestStart(t *testing.T) { + data := NewData() + data.id = "1" + data.msg["1"] = "1" + data.toolscall = []*MiddlewareConf{} + data.waitchanle = "1" + Start(data) +} -- Gitee From 6952132386d901676bd0dbbb8ed2e654f1826aa2 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Tue, 21 Sep 2021 14:31:57 +0800 Subject: [PATCH 4/4] "driver doc" --- pkg/middle/data.go | 28 ++++++++++++----- pkg/middle/driver.go | 27 ++++++++++++++-- pkg/middle/middle.go | 73 +++++++++++++++++++++----------------------- 3 files changed, 79 insertions(+), 49 deletions(-) diff --git a/pkg/middle/data.go b/pkg/middle/data.go index 18dcc80..d41adf9 100644 --- a/pkg/middle/data.go +++ b/pkg/middle/data.go @@ -2,23 +2,35 @@ package middle // 数据类型 type data struct { - m map[string]interface{} + id string + toolscall []*MiddlewareConf + msg map[interface{}]interface{} + waitchanle interface{} } // 数据初始化,分配内存 func NewData() *data { - return &data{ - make(map[string]interface{}), - } + return new(data) } // 获取数据 -func (d *data) Get(key string) interface{} { - return d.m[key] +func (d *data) get_Msg(id string) interface{} { + return d.msg["id"] +} + +func (d *data) get_toolscall() []*MiddlewareConf { + return d.toolscall +} + +func (d *data) get_waitchanle() interface{} { + return d.waitchanle } // 推入数据 -func (d *data) Put(key string, val interface{}) error { - d.m[key] = val +func (d *data) Put(id string, toolscall []*MiddlewareConf, msg map[interface{}]interface{}, waitchanle interface{}) error { + d.id = id + d.msg = msg + d.toolscall = toolscall + d.waitchanle = waitchanle return nil } diff --git a/pkg/middle/driver.go b/pkg/middle/driver.go index 2ea8b57..929d237 100644 --- a/pkg/middle/driver.go +++ b/pkg/middle/driver.go @@ -1,15 +1,38 @@ package middle -type eventQueueApi interface { +import "fmt" + +type EventQueueApi interface { Put(key string, val interface{}) Get(key string) interface{} Start() } type driver struct { - conf []*MiddlewareConf + queue []*data } func Newdriver() *driver { return new(driver) } + +func (d *driver) Put(data *data) { + d.queue = append(d.queue, data) +} + +func (d *driver) Get(id string) interface{} { + for _, data := range d.queue { + if data.id == id { + return data + } + } + return "no exist this data" +} + +func Start(data *data) { + driver := Newdriver() + driver.Put(data) + for _, data := range driver.queue { + fmt.Println(data.id) + } +} diff --git a/pkg/middle/middle.go b/pkg/middle/middle.go index 2c0e1a4..37ca607 100644 --- a/pkg/middle/middle.go +++ b/pkg/middle/middle.go @@ -1,14 +1,14 @@ package middle // 获取数据的接口 -type Msg interface { +type MiddleApi interface { Put(key string, val interface{}) error Get(key string) interface{} } type middleWare interface { - Put(msg Msg) - Out() Msg + Put(msg MiddleApi) + Out() MiddleApi } type MiddlewareConf struct { @@ -24,39 +24,34 @@ func NewDriver() *Driver { return new(Driver) } -// 驱动 -func (d *Driver) Start(msg Msg) { - - for _, m := range d.conf { - - go m.Middle.Put(msg) - - msg = m.Middle.Out() - - } - -} - -func main() { - conf := []*MiddlewareConf{ - { - Weight: 1, - Middle: NewUpload(), - }, - { - Weight: 2, - Middle: NewStorage(), - }, - { - Weight: 3, - Middle: NewSend(), - }, - } - - da := NewDriver() - da.conf = conf - val := NewData() - val.Put("200", 2) - - da.Start(val) -} +// // 驱动 +// func (d *Driver) Start() { +// conf := []*MiddlewareConf{ +// { +// Weight: 1, +// Middle: NewUpload(), +// }, +// { +// Weight: 2, +// Middle: NewStorage(), +// }, +// { +// Weight: 3, +// Middle: NewSend(), +// }, +// } + +// da := NewDriver() +// da.conf = conf +// val := NewData() +// val.Put("200", 2) + +// for _, m := range d.conf { + +// go m.Middle.Put(val) + +// msg := m.Middle.Out() +// fmt.Println(msg) +// } + +// } -- Gitee