Golang Web框架Buffalo 简单使用

官方文档 https://gobuffalo.io 安装 安装要求 Before installing make sure you have the required dependencies installed: A working Go environment Go version v1.16.0. Frontend Requirements# The following requirements are optional. You don’t need them if you want to build an API or if you prefer to build your app in an old-fashioned way. node version 8 or greater either yarn or npm for the asset pipeline built upon webpack. Database Specific Requirements# Again, if you don’t need a database, you won’t need these....

January 29, 2023 · 1 min · czyt

从Golang的开源项目中学习不同的功能实现

缘起 最近看到有些go开源项目中的代码,看到其中的功能,故整理备用。 数据结构 优先级队列 项目 https://github.com/tigrisdata/tigris // Copyright 2022-2023 Tigris Data, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied....

November 25, 2022 · 14 min · czyt

C#扫码枪输入Hook

摘自网络,测试可用 public class ScanerHook { public delegate void ScanerDelegate(ScanerCodes codes); public event ScanerDelegate ScanerEvent; //private const int WM_KEYDOWN = 0x100;//KEYDOWN //private const int WM_KEYUP = 0x101;//KEYUP //private const int WM_SYSKEYDOWN = 0x104;//SYSKEYDOWN //private const int WM_SYSKEYUP = 0x105;//SYSKEYUP //private static int HookProc(int nCode, Int32 wParam, IntPtr lParam); private int hKeyboardHook = 0;//声明键盘钩子处理的初始值 private ScanerCodes codes = new ScanerCodes();//13为键盘钩子 //定义成静态,这样不会抛出回收异常 private static HookProc hookproc; delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); [DllImport("user32....

November 1, 2022 · 4 min · czyt

使用protoc-gen-star编写protoc插件

预备知识 需要安装的软件 protoc golang go 软件包 github.com/lyft/protoc-gen-star 插件调用步骤 protoc,PB编译器,使用一组标志(记录在protoc -h下)进行配置,并将一组文件作为参数交给它。在这种情况下,I标志可以被多次指定,是它在proto文件中用于导入依赖关系的查找路径。默认情况下,官方描述符protos已经被包含在内。 myplugin_out 告诉 protoc 使用 protoc-gen-myplugin protoc-plugin。这些插件会从系统的 PATH 环境变量中自动解析,或者可以用另一个标志明确指定。官方的protoc-plugins (例如,protoc-gen-python) 已经在protoc注册了。该标志的值是特定于特定插件的,但 :…/generated 后缀除外。这个后缀表示protoc将把该包生成的文件放在哪个根目录下(相对于当前工作目录)。然而,这个生成的输出目录不会传播给 protoc-gen-myplugin,所以它需要在标志的左边重复。PG* 通过一个 output_path 参数支持这一点。 protoc 解析传入的 proto 文件,确保它们在语法上是正确的,并加载任何导入的依赖项。它将这些文件和依赖关系转换成描述符 (它们本身就是 PB 消息),并创建一个 CodeGeneratorRequest (又是一个 PB)。protoc 将这个请求序列化,然后执行每个配置的 protoc-plugin,通过 stdin 发送有效载荷。 protoc-gen-myplugin 启动,接收请求的有效载荷,并将其解密。一个基于 PG* 的 protoc-plugin 有两个阶段。首先,PG* 对从 protoc 收到的 CodeGeneratorRequest 进行解密,并为每个文件和其包含的所有实体创建一个完全连接的抽象语法树 (AST)。为这个插件指定的任何参数也会被解析,以便以后使用。 当这一步完成后,PG*就会执行任何注册的模块,把构建的AST交给它。模块可以被写成生成人工制品(例如,文件),或者只是对所提供的图进行某种形式的验证而没有任何其他副作用。模块在针对PB的操作方面提供了极大的灵活性。 一旦所有的模块都被运行,PG*会将任何自定义的工件写入文件系统,或者将生成器特定的工件序列化为CodeGeneratorResponse并将数据发送到其stdout。这整个流程看起来像这样。 foo.proto → protoc → CodeGeneratorRequest → protoc-gen-myplugin → CodeGeneratorResponse → protoc → foo.pb.go 假设插件名称为diy,则需要编译程序为protoc-gen-diy,并将程序加入系统Path变量,通过下面的命令调用插件。 protoc -I ....

October 29, 2022 · 3 min · czyt

C# dllimport 备忘录

dllImport的入口点问题 通过Dependencies查询Dll对应方法的EntryPoint 然后在dllimport的attribute中显式申明EntryPoint [DllImport("demo.dll", SetLastError = true,EntryPoint ="[email protected]@Gfeit@@[email protected]")] public static extern IntPtr DemoManager(); 导入类方法的问题 最好的方式还是使用C++构造wrapper,然后通过windowsApi的方式调用Pinvoke 参考链接 swig nuget swig C++/C# interoperability Working with C++ Interface Classes from C# Call function in unmanaged DLL from C# and pass custom data types [Marshal] SWIG and C# Example for SWIG to wrap C++ library in .Net 6

October 9, 2022 · 1 min · czyt

tailscale的泛型SingleFlight

源地址 tailscale仓库 完整代码如下 // Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package singleflight provides a duplicate function call suppression // mechanism....

September 23, 2022 · 5 min · czyt

Rasp3b 安装Postgresql

安装 系统信息 使用命令安装 yay -S postgresql 初始化及配置 启用数据库服务 sudo systemctl enable --now postgresql 开启数据库服务 sudo systemctl start postgresql 初始化数据 su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'" 查询配置文件路径 su - postgres [[email protected] ~]$ ls data [[email protected] ~]$ psql psql (14.5) 输入 "help" 来获取帮助信息. postgres=# SHOW config_file; config_file ---------------------------------------- /var/lib/postgres/data/postgresql.conf (1 行记录) 修改监听 修改配置/var/lib/postgres/data/postgresql.conf 文件中的listen_addresses = '*'监听所有地址,重启服务sudo systemctl restart postgresql生效。 允许远程访问 修改配置文件同级目录下的pg_hba.conf,添加一行 # TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 0....

September 17, 2022 · 1 min · czyt

.NET6 从JSON获取配置

环境准备 nuget包 Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration.Binder Microsoft.Extensions.Configuration.Json (当需要从Json文件添加记录时,安装此nuget包) Microsoft.Extensions.Configuration.EnvironmentVariables (当需要从环境变量添加记录时,安装此nuget包) C#开发环境 visual studio 2019 + visual Code 示例代码 // See https://aka.ms/new-console-template for more information using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; Console.WriteLine("Hello, World!"); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); IConfiguration c = configurationBuilder.AddJsonFile("appsettings.json").AddEnvironmentVariables().Build(); var k = c.GetRequiredSection("Settings").Get<Settings>().KeyOne; var n = 1; public class NestedSettings { public string Message { get; set; } = null!; } public class Settings { public int KeyOne { get; set; } public bool KeyTwo { get; set; } public NestedSettings KeyThree { get; set; } = null!...

September 6, 2022 · 1 min · czyt

浅谈windows默认Shell的替换

Windows XP时代 Xp时代提供的是通过注册表来自定义shell 设置所有用户的shell 注册表键HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell 设置当前用户的shell注册表键 HKEY_Current_User\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell 注册表键值类型 REG_SZ 值修改为你要自定义为shell的程序的完整路径。 在windows10下使用该技巧可能会出现黑屏的现象,参考stackoverflow的回答 Simply replacing the “explorer.exe” (HKLM\SOFTWARE\Microsoft\Window NT\Winlogon\Shell) with a custom app location provided a black screen. A much simpler way, and it works great, was to create a BATCH script to call the custom app through elevated powershell… powershell -nologo -noprofile -executionpolicy bypass -command "start-process -verb 'runas' -filepath <full path of custom app executable>" By replacing “explorer.exe” with this batch script I was able to successfully create a kiosk style lockdown under Windows 10 PRO with a non-UWP app....

August 31, 2022 · 2 min · czyt

Golang 默认的CGO参数编译导致的GLIBC错误

问题描述 使用go正常编译了Linux下的程序,放到服务器上报错 ./app: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./app) 解决 Google了下,发现相同的Issue,于是通过go env检查本机golang运行环境,发现CGO默认启用而且程序也不涉及CGO相关的东西,于是设置CGO参数为关闭。然后编译程序 CGO_ENABLED="0" go build -v 重新上传,运行OK.

August 30, 2022 · 1 min · czyt