后端,笔记
个人笔记本

HTTP generate_204 检测网络连接是否正常

generate_204 是一个网络请求的特殊 URL,通常用于检测网络连接是否正常。当设备连接到一个需要认证的网络时,例如公共 Wi-Fi 或企业网络,设备会在浏览器中请求 generate_204 页面,以验证网络连接是否成功。

具体来说,当设备连接到一个需要认证的网络时,设备会尝试访问一个特定的 URL(通常是 generate_204)来检测网络连接状态。如果网络连接正常,服务器会返回一个非空的 HTTP 响应,通常是一个空白页面或一个特定的响应码(如 204 No Content)。这表明设备已成功连接到网络,并且可以正常访问互联网。

阅读全文»

VYOS 开源路由简易编译教程/镜像构建

这是一篇简短的文章,展示了如何构建自己的 VyOS LTS iso 映像。已经在 Debian Buster(Debian 10)通过测试!~

安装 Docker

$ sudo apt-get update
$ sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install -y docker-ce

$ sudo usermod -aG docker <Your username>

注:国内网络环境可参考 https://mirror.tuna.tsinghua.edu.cn/help/docker-ce/

阅读全文»

VYOS 安装与基础命令

安装

vyos@vyos:~$ install image
Welcome to the VyOS install program.  This script
will walk you through the process of installing the
VyOS image to a local hard drive.
Would you like to continue? (Yes/No) [Yes]: Yes
Probing drives: OK
Looking for pre-existing RAID groups...none found.
The VyOS image will require a minimum 2000MB root.
Would you like me to try to partition a drive automatically
or would you rather partition it manually with parted?  If
you have already setup your partitions, you may skip this step
 
Partition (Auto/Parted/Skip) [Auto]:
 
I found the following drives on your system:
 sda    4294MB
 
Install the image on? [sda]:
 
This will destroy all data on /dev/sda.
Continue? (Yes/No) [No]: Yes
 
How big of a root partition should I create? (2000MB - 4294MB) [4294]MB:
 
Creating filesystem on /dev/sda1: OK
Done!
Mounting /dev/sda1...
What would you like to name this image? [1.2.0-rolling+201809210337]:
OK.  This image will be named: 1.2.0-rolling+201809210337
Copying squashfs image...
Copying kernel and initrd images...
Done!
I found the following configuration files:
    /opt/vyatta/etc/config.boot.default
Which one should I copy to sda? [/opt/vyatta/etc/config.boot.default]:
 
Copying /opt/vyatta/etc/config.boot.default to sda.
Enter password for administrator account
Enter password for user 'vyos':
Retype password for user 'vyos':
I need to install the GRUB boot loader.
I found the following drives on your system:
 sda    4294MB
 
Which drive should GRUB modify the boot partition on? [sda]:
 
Setting up grub: OK
Done!



vyos@vyos:~$ reboot
Proceed with reboot? (Yes/No) [No] Yes

阅读全文»

Golang 第三方库学习 · xlsx

介绍

xlsx 是对新版本的Excel进行简单读写操作的golang第三方库,支持的文件格式是.xlsx

源码

第三方库源码:
https://github.com/tealeg/xlsx

本文源码:
https://github.com/Chain-Zhang/third-lib

安装

go get github.com/tealeg/xlsx



阅读全文»

Golang 源码解析 DetectContentType 检测文件类型

我们可以使用 golang 中的 net/http 包的来查找文件的内容类型或 mime 类型。

DetectContentType 函数实现了 http://mimesniff.spec.whatwg.org/ 描述的算法,用于确定数据的 Content-Type .

该函数会检查数据的前 512 字节,然后返回一个合法的 MIME 类型,例如 application/json 或类似 image/jpg .

如果不能确定数据的类型,将返回 "application/octet-stream" .

阅读全文»