博客

  • Visual Studio 多环境并存

    有时会遇到这样的问题,在使用VS 时,对不同的语言,需要不同的插件支持,VS配置。 有一个办法是同时使用多个版本的VS,但这很让人不爽。

    VisualStudio 有一个高级的用法,在命令行后添加 /rootSuffix ,可以创建一个完全不同的环境。在开发 VS插件时,开启调试,会创建一个完全空白的VS并加载这个插件,就是通过这个配置完成的。

    1. 创建一个新的 Visual Studio 的快捷方式

    可以通过复制旧快捷方式完成

    2. 右键属性修改快捷方式启动命令

    此时,启动该快捷方式,得到的就是一个新的vs

    到扩展里安装插件吧。

  • VSCode 使用docker-compose进行golang开发

    O 前言

    在网上搜索使用vscode 进行golang的docker配置,有大量的文章,在官网也有很详细的说明,但我就是看不明白!!

    自己搞了一晚上,总算把所有的坑填上了。记录一下,聊以自慰。

    一、 前置操作

    安装vscode 略

    安装golang 略

    golang使用module 模式而非 GOPATH, 略

    vscode 中安装 remote-containers 插件,略

    二、新建go 项目

    1. 创建文件夹 /golang/study.06, 并使用 vscode 打开。
    2. 新建main.go 我这里使用`
    package main
    
    import (
      "fmt"
      "log"
      "net/http"
    )
    
    func homepage(w http.ResponseWriter, r *http.Request) {
      // 显示内容
      fmt.Fprintf(w, "Hello golang http in docker!")
    }
    
    func main() {
      // 设置路由
      http.HandleFunc("/", homepage)
    
      // 启动web服务,监听 9090
      log.Fatel(http.ListenAndServe(":9090", nil))
    
    }
    
    1. 初始化模块
    # 初始化模块
    go mod init study06
    
    # 下载依赖模块
    go mod tidy
    
    
    1. 测试
    # 启动服务
    go run .
    
    

    在浏览器查看http://localhost:9090 ,可以看到效果。

    1. 文件目录
    study.06
    |-- go.mod
    |-- main.go
    

    三、添加docker-compose支持

    1. 添加模板

    执行 F1Remote-Containers: Add Development Container Configuration Files,依次选择 Godefaultlts(default)确定

    此时,添加了 .devcontainer/.devcontiner.json.devcontaier/Dockerfile两个文件。

    2. 使用docker-compose

    .devcontainer中添加docker-compose.yml,也可以多添加几个配置,如docker-compose.dev.yml

    # docker-compose.yml
    
    version: '3'
    
    services:
      study-06:
        build:
          context: .
          dockerfile: Dockerfile
          
    
    # docker-compose.dev.yml
    
    version: '3'
    
    services:
      study-06:
        build:
          context: .
          dockerfile: Dockerfile
        volumes:
          - ..:/workspace:cached
        ports:
          - 9090:9090
    
        cap_add:
          - SYS_PTRACE
    
        security_opt:
          - seccomp:unconfined
        
        command: /bin/sh -c "while sleep 1000; do :; done"
    
      
    
    
    

    3. 修改 devcontainer.json

    默认配置是使用Dockerfile的,修改devcontainer.json 以使用docker-compose

    // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
    // https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/go
    {
      "name": "Go",
      "dockerComposeFile" : [
        "docker-compose.yml",
        "docker-compose.dev.yml"
      ],
      "service" : "study-06",
      "workspaceFolder": "/workspace",
      "shutdownAction": "stopCompose",
      // "build": {
      //   "dockerfile": "Dockerfile",
      //   "args": {
      //     // Update the VARIANT arg to pick a version of Go: 1, 1.16, 1.17
      //     // Append -bullseye or -buster to pin to an OS version.
      //     // Use -bullseye variants on local arm64/Apple Silicon.
      //     "VARIANT": "1-bullseye",
      //     // Options
      //     "NODE_VERSION": "lts/*"
      //   }
      // },
      // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
    
      // Set *default* container specific settings.json values on container create.
      "settings": {
        "go.toolsManagement.checkForUpdates": "local",
        "go.useLanguageServer": true,
        "go.gopath": "/go",
        "go.goroot": "/usr/local/go"
      },
    
      // Add the IDs of extensions you want installed when the container is created.
      "extensions": [
        "golang.Go"
      ],
    
      // Use 'forwardPorts' to make a list of ports inside the container available locally.
      // "forwardPorts": [],
    
      // Use 'postCreateCommand' to run commands after the container is created.
      // "postCreateCommand": "go version",
    
      // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
      "remoteUser": "vscode"
    }
    
    

    4. 修改Dockerfile

    最后添加 Expose 9090 绑定端口

    5. 在容器中打开文件夹

    F1 执行 Open Folder in Container,选择 study.06目录,此时vscode会编译并运行镜像,进入镜像中的环境。

    执行 go run .,就可以在 http://localhost:9090 中看到结果了。

    6. 更新

    如果对docker文件进行任何修改后,可以执行 F1 -> Rebuild 重新生成镜像

  • wpf 绑定ListViewItem

    Wpf 绑定ListViewItem 中的控件 Command 到 ViewModel :

    1. 给Window​ ** 定义名字:**

     <Window x:Name= "ThisWnd" >
    
    

    在绑定时找到指定名字

     <ListView>
     
         <ListView.ItemTemplate>
     
             <DataTemplate>
     
                 <Button Command= "{Binding ElementName=ThisWnd, Path=DataContext.CallCommand}" 
                 Text={Binding Name}></Button>
    
    

    2. 相对路径查找

    另一种方式是根据类型或层次查找

     <ListView>
     
         <ListView.ItemTemplate>
     
             <DataTemplate>
     
                 <Button Command= "{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.CallCommand}" 
                 Text={Binding Name}></Button>
     
     
    
    
  • xmake 配置代理

    Network Optimization | Xmake

    xmake下载库时,默认不使用代理,所以经常下载失败,需要手动配置代理:

    xmake g --proxy="socks5://127.0.0.1:33211"
    

    3312 是我使用的vpn的默认端口

    也可以配置 github镜像,我没使用这个方法。

    Network Optimization | Xmake

  • 世界,您好!

    欢迎使用 WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!