<ruby id="dzldf"></ruby>

<span id="dzldf"><th id="dzldf"></th></span>
<em id="dzldf"><form id="dzldf"></form></em>
<address id="dzldf"></address>

<form id="dzldf"><th id="dzldf"><progress id="dzldf"></progress></th></form>

    <form id="dzldf"></form>
    <em id="dzldf"><address id="dzldf"></address></em>

    葵花宝典教程,一个自学编程平台

    葵花宝典教程,一个自学编程平台

    sudo go 提示找不到命令:sudo: go: command not found

    环境变量配置:

    # ~/.bash_profile

    export GOROOT=/usr/local/go

    export GOPATH=/usr/local/GO

    export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

    错误描述:

    使用非root用户,执行 go version 获得正确输出。

    使用root用户,执行 go verison 获得正确输出。

    使用非root用户,执行 sudo go version 获得输出 sudo: go: command not found。

    解决办法:

    根据 Some programs not found when used with sudo 中的回答。


    我们使用 sudo 时,使用的配置文件是 /etc/sudoers。


    配置 /etc/sudoers 文件中的 Defaults secure_path 这一项。将 $GOROOT/bin 目录加入进去。(请使用绝对目录,如:/usr/local/go/bin/)


    Defaults secure_path 这一行:

    Defaults    secure_path = /usr/local/go/bin/:/sbin:/bin:/usr/sbin:/usr/bin

    go mod tidy 报错:XXXX found,but does not contain package XXXX

    举个例子:

    gitee.com/atix/utils/logger: module gitee.com/atix/utils@latest found (v0.1.0), but does not contain package gitee.com/atix/utils/logger

    来看上文这个报错,由于我们 import 时未指定特定版本号,故 golang 默认使用最新版本(即能够通过 git checkout 将其检出的版本号),我们去查看该 module,发现有一个 tag 号为:v0.1.0,检查该 tag 代码发现确实没有我们要用的 logger 包,由此判断是我们 import 了一个尚未发布的 package,碰到这种情况只需要将该 module 重新打个 tag,将我们用到的 package 发布,然后本地执行:

    go get gitee.com/atix/utils@v0.1.1 把新的版本下载、安装到本地,之后就正常了。

    go get  github.com/aaa/lotus@latest    [最新版]

    Lotus

    Lotus 是 Filecoin 分布式存储网络的实现。

    基本构建说明

    构建 Lotus 需要一些系统依赖项,这些依赖项通常由您的发行版提供。

    Ubuntu/Debian:


    sudo apt install mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y && sudo apt upgrade -y


    要构建 Lotus,您需要安装Go 1.16.4 或更高版本

    wget -c https://golang.org/dl/go1.16.4.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

    提示:您需要添加/usr/local/go/bin到您的路径。对于大多数 Linux 发行版,您可以运行以下命令:


    echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc && source ~/.bashrc

    构建和安装 Lotus

    一旦安装了所有依赖项,您就可以构建和安装 Lotus 套件(lotuslotus-minerlotus-worker)。

    1克隆存储库:

    git clone https://github.com/filecoin-project/lotus.git

    cd lotus/

    注意:默认分支master是最新的新功能

    2要加入主网

    git checkout < tag_or_branch > #例如: 
    git checkout < vX.XX >  #发布标签
    
    目前master分支上的最新代码对应主网。
    
    3如果您在中国
    4此构建指令使用预构建的证明二进制文件[请注意,如果您从源代码构建证明二进制文件,则还需要安装 rustup 。]
    5构建和安装 Lotus
    
    make clean all #mainnet
    
    # Or to join a testnet or devnet:
    make clean calibnet # Calibration with min 32GiB sectors
    
    sudo make install
    
    lotus将$HOME/.lotus默认使用该文件夹进行存储(配置、链数据、钱包等)。


    6您现在应该已经安装了 Lotus。


    [

    https://github.com/filecoin-project/lotus

    ]

    filecoin安装条件

    最低要求

    要运行 Lotus 节点,您的计算机必须具备:


    已安装 macOS 或 Linux。尚不支持 Windows。

    8 核 CPU 和 32 GiB RAM。支持英特尔 SHA 扩展(自 Zen 微架构以来的 AMD 或自 Ice Lake 以来的英特尔)的模型将显着加快速度。

    足够的空间来存储当前的 Lotus 链(最好在 SSD 存储介质上)。该链以每天大约 38 GiB 的速度增长。该链可以从受信任的状态快照同步,并压缩或修剪到最小大小约为 33Gib。2021 年 6 月的完整历史记录约为 10TiB。

    中国节点加速

    运行 Lotus 需要下载链的证明参数,这些文件是大文件,默认托管在中国境外,在那里下载非常慢。为了解决这个问题,用户应该在运行 和 时设置以下lotus环境lotus-miner变量lotus-worker

    export IPFS_GATEWAY=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/


    构建 Lotus 需要下载一些 Go 模块。这些通常托管在 Github 上,来自中国的带宽非常低。要解决此问题,请在运行 Lotus之前通过设置以下变量来使用本地代理:

    export GOPROXY=https://goproxy.cn


    在 Linux 上安装 Lotus 有几种方法:


    • Snap package manager

    • AppImages

    • Building from source.





    go面试题

    Go学习-make和new的区别

    https://blog.csdn.net/ouyangyiwen/article/details/111548053

    [

    new和make的区别,我们从下图便可看出:

             1)new是为值类型分配内存(可以任意类型的数据),其返回的是指针,指向分配类型的内存地址。         

             2)make为引用类型分配内存并初始化,如:chan、map和slice,其返回值为这个类型(引用)本身。   

             3)new 分配的空间被清零。make 分配空间后,会进行初始化;

    ]

    golang切片和数组的区别


    数组是值拷贝而切片是引用

    https://www.cnblogs.com/blog-196/p/11141356.html

    Go语言切片详解 

    https://www.cnblogs.com/lvnux/p/12907356.html


    goland使用go mod模式

    使用go mod之后,想要在goland中有代码提示,有两种方式,一种是使用gopath下的goimport工具,另一种是使用gomod自身的管理工具

    我是用的是非gopath的方式,每次新建项目后总是报错

    go list -m: can‘t compute ‘all‘ using the vendor directory
    (Use -mod=mod or -mod=readonly to bypass.),

    得不到想要的效果,最后终于发现是步骤不对

    第一步:创建空文件夹

    第二步:goland以项目方式打开文件夹

    第三步:设置goland中的配置,goroot,gomodule


    1-1.png

    第四步:执行go mod init + 项目名,这个截图的地方多一个go modules,用于存放下载的包的


    2-2.png

    第五步:创建.go文件,然后写上代码

    第六步:执行go mod tidy,下载所需的包,也会删除多余的包


    Laravel DB::table update record

    I have this query

     DB::table('product_options')
            ->where('product_id', $id)
            ->where('size', $selected_size)
            ->update(array('stock' => WHAT TO PUT HERE));

    In the update part where I've put WHAT TO UPDATE, what should I put here to decrease the number by 1?

    DB::table('product_options')
            ->where('product_id', $id)
            ->where('size', $selected_size)
            ->decrement('stock');


    当 Target 类 [Controller] 不存在时怎么办. 出现在 Laravel

    在最近的 Laravel(可能是 v8 或更高版本)中,如果你在初始状态下在 routes/web.php 中编写以下代码,你将无法找到应该在那里的 Controller Class,并且会出现错误。

    Route::get('/hoge', 'Controller@index');
    Illuminate\Contracts\Container\BindingResolutionException Target class [Controller] does not exist.  http://laravel.internal/hoge  Illuminate\Container\Container::build htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:811

    显然,我开始忘记了 Contoller 的初始位置。

    一致

    $namespace取消注释App / Providers / RouteServiceProvider.php

        /**      
        * The controller namespace for the application.      *      
        * When present, controller route declarations will automatically be prefixed with this namespace.           
        * @var string|null      
        */     
        protected $namespace = 'App\\Http\\Controllers'; //


    python字符串连接的几种方法

    python字符串连接的方法,一般有以下三种:

    方法1:直接通过加号(+)操作符连接

    1
    website = 'python' + 'tab' + '.com'

    方法2:join方法

    1
    2
    listStr = ['python''tab''.com'
    website = ''.join(listStr)

    方法3:替换

    1
    website = '%s%s%s' % ('python''tab''.com')

    下面再来说一下三种方法的不同

    方法1,使用简单直接,但是网上不少人说这种方法效率低

    之所以说python 中使用 + 进行字符串连接的操作效率低下,是因为python中字符串是不可变的类型,使用 + 连接两个字符串时会生成一个新的字符串,生成新的字符串就需要重新申请内存,当连续相加的字符串很多时(a+b+c+d+e+f+...) ,效率低下就是必然的了

     

    方法2,使用略复杂,但对多个字符进行连接时效率高,只会有一次内存的申请。而且如果是对list的字符进行连接的时候,这种方法必须是首选

     

    方法3:字符串格式化,这种方法非常常用,本人也推荐使用该方法


    Python爬虫常用库总结之“Requests”

    Requests模块介绍:

    发送http请求,获取响应数据

    requests模块是一个第三方模块,需要在你的python(虚拟)环境中额外安装: 

    pip/pip3 install requests

    requests基础:

    requests模块发送get请求


    • import requests

    • # 目标url

    • url = 'https://www.baidu.com'

    • # 向目标url发送get请求

    • response = requests.get(url)

    • # 打印响应内容

    • print(response.text)


    Response响应对象:

    观察上边代码运行结果发现,有好多乱码;这是因为编解码使用的字符集不同造成的;我们尝试使用下边的办法来解决中文乱码问题


    • import requests

    • url = 'https://www.baidu.com'

    • # 向目标url发送get请求

    • response = requests.get(url)

    • # 打印响应内容

    • # print(response.text)

    • print(response.content.decode()) # 注意这里!


    1、response.text是requests模块按照chardet模块推测出的编码字符集进行解码的结果

    2、网络传输的字符串都是bytes类型的,所以response.text = response.content.decode(‘推测出的编码字符集’)

    3、我们可以在网页源码中搜索charset,尝试参考该编码字符集,注意存在不准确的情况。


    Response.text 和Response.content的区别:

    1、Response.text


    • 类型:str

    • 解码类型: requests模块自动根据HTTP 头部对响应的编码作出有根据的推测,推测的文本编码


    2、Response.content


    • 类型:bytes

    • 解码类型: 没有指定



    解决中文乱码:

    通过对response.content进行decode,来解决中文乱码


    1、Response.content.decode() 默认utf-8

    2、Response.content.decode("GBK")

    3、常见的编码字符集

    • utf-8

    • gbk

    • gb2312

    • ascii (读音:阿斯克码)

    • iso-8859-1



    Response响应对象的其它常用属性或方法:


    • #https://beishan.blog.csdn.net/

    • # 1.2.3-response其它常用属性

    • import requests


    • # 目标url

    • url = 'https://www.baidu.com'


    • # 向目标url发送get请求

    • response = requests.get(url)


    • # 打印响应内容

    • # print(response.text)

    • # print(response.content.decode()) # 注意这里!

    • print(response.url)# 打印响应的url

    • print(response.status_code)# 打印响应的状态码

    • print(response.request.headers)# 打印响应对象的请求头

    • print(response.headers)# 打印响应头

    • print(response.request._cookies)# 打印请求携带的cookies

    • print(response.cookies)# 打印响应中携带的cookies



    Requests实操:

    requests模块发送请求

    发送带header的请求

    我们先写一个获取百度首页的代码



    • import requests

    • url = 'http://www.bstarfood.com'

    • response = requests.get(url)

    • print(response.content.decode())

    • # 打印响应对应请求的请求头信息

    • print(response.request.headers)


    从浏览器中复制User-Agent,构造Headers字典;完成下面的代码后,运行代码查看结果


    • import requests


    • url = 'http://www.bstarfood.com'


    • headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}


    • # 在请求头中带上User-Agent,模拟浏览器发送请求

    • response = requests.get(url, headers=headers)


    • print(response.content)


    • # 打印请求头信息

    • print(response.request.headers)


    发送带参数的请求:

    我们在使用百度搜索的时候经常发现url地址中会有一个 ?,那么该问号后边的就是请求参数,又叫做查询字符串


    在url携带参数,直接对含有参数的url发起请求


    • import requests


    • headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}


    • url = 'https://www.baidu.com/s?wd=python'


    • response = requests.get(url, headers=headers)



    通过Params携带参数字典:

    1.构建请求参数字典

    2.向接口发送请求的时候带上参数字典,参数字典设置给params


    • import requests


    • headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}


    • # 这是目标url

    • # url = 'https://www.baidu.com/s?wd=python'


    • # 最后有没有问号结果都一样

    • url = 'https://www.baidu.com/s?'


    • # 请求参数是一个字典 即wd=python

    • kw = {'wd': 'python'}


    • # 带上请求参数发起请求,获取响应

    • response = requests.get(url, headers=headers, params=kw)


    • print(response.content)

    • 从浏览器中复制User-Agent和Cookie

    • 浏览器中的请求头字段和值与headers参数中必须一致

    • headers请求参数字典中的Cookie键对应的值是字符串

    • import requests


    • url = 'https://github.com/USER_NAME'


    • # 构造请求头字典

    • headers = {

    • # 从浏览器中复制过来的User-Agent

    • 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',

    • # 从浏览器中复制过来的Cookie

    • 'Cookie': 'xxx这里是复制过来的cookie字符串'

    • }


    • # 请求头参数字典中携带cookie字符串

    • resp = requests.get(url, headers=headers)


    • print(resp.text)




    超时参数timeout的使用:

    在平时网上冲浪的过程中,我们经常会遇到网络波动,这个时候,一个请求等了很久可能仍然没有结果。

    在爬虫中,一个请求很久没有结果,就会让整个项目的效率变得非常低,这个时候我们就需要对请求进行强制要求,让他必须在特定的时间内返回结果,否则就报错。


    1、超时参数timeout的使用方法

    response = requests.get(url, timeout=3)

    2、timeout=3表示:发送请求后,3秒钟内返回响应,否则就抛出异常


    • import requests



    • url = 'https://twitter.com'

    • response = requests.get(url, timeout=3) # 设置超时时间



    Requests发送post请求的方法:


    • response = requests.post(url, data)

    • data参数接收一个字典

    • requests模块发送post请求函数的其它参数和发送get请求的参数完全一致


    注意运行的时候开梯子就会报错



    << 1 2 3 4 5 6 7 8 9 10 > >>

    Copyright www.bstarfood.com Rights Reserved葵花宝典教程.鄂icp2022001145号-1

    分享:

    支付宝

    微信

    找妓女网站 最新中文字幕无码AⅤ专区 色综合久久九月婷婷色综合 国产一级a毛一级a做免费视频无码 国产精品视频91 亚洲美女激情视频
    <ruby id="dzldf"></ruby>

    <span id="dzldf"><th id="dzldf"></th></span>
    <em id="dzldf"><form id="dzldf"></form></em>
    <address id="dzldf"></address>

    <form id="dzldf"><th id="dzldf"><progress id="dzldf"></progress></th></form>

      <form id="dzldf"></form>
      <em id="dzldf"><address id="dzldf"></address></em>