Mac通过内网IP获取同一内网下的设备名称


1
2
3
4
5
6
7
8
9
10
➜  ~ brew install --cask bonjour-browser
Error: Download failed on Cask 'bonjour-browser' with message: Failure while executing; `/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.1.6-26-gb69bd66\ \(Macintosh\;\ arm64\ Mac\ OS\ X\ 14.5\)\ curl/8.6.0 --header Accept-Language:\ en --retry 3 --fail --location --silent --head --request GET https://www.tildesoft.com/files/BonjourBrowser.dmg` exited with 8. Here's the output:
curl: (8) Weird server reply
HTTP/2 200
accept-ranges: bytes
etag: "q2kr7s475b"
last-modified: Sun, 15 Dec 2019 22:16:40 GMT
server: Caddy
content-length: 195887
date: Tue, 03 Sep 2024 08:01:41 GMT

bonjour-browser貌似只适用于intel芯片的,还没适配吧..

PV操作

什么是信号量

1
2
3
4
5
6
7
计数信号量具备两种操作动作,称为V(signal())与P(wait())(即部分参考书常称的“PV操作”)。V操作会增加信号量S的数值,P操作会减少它。

运行方式:

初始化信号量,给与它一个非负数的整数值。
运行P(wait()),信号量S的值将被减少。企图进入临界区的进程,需要先运行P(wait())。当信号量S减为负值时,进程会被阻塞住,不能继续;当信号量S不为负值时,进程可以获准进入临界区。
运行V(signal()),信号量S的值会被增加。结束离开临界区的进程,将会运行V(signal())。当信号量S不为负值时,先前被阻塞住的其他进程,将可获准进入临界区。

一些代码优化方式

https://github.com/grpc/grpc-go/pull/7525

https://github.com/open-telemetry/opentelemetry-go/blob/metric/v1.28.0/metric/instrument.go#L349-L368

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// WithAttributes converts attributes into an attribute Set and sets the Set to
// be associated with a measurement. This is shorthand for:
//
// cp := make([]attribute.KeyValue, len(attributes))
// copy(cp, attributes)
// WithAttributes(attribute.NewSet(cp...))
//
// [attribute.NewSet] may modify the passed attributes so this will make a copy
// of attributes before creating a set in order to ensure this function is
// concurrent safe. This makes this option function less optimized in
// comparison to [WithAttributeSet]. Therefore, [WithAttributeSet] should be
// preferred for performance sensitive code.
//
// See [WithAttributeSet] for information about how multiple WithAttributes are
// merged.
func WithAttributes(attributes ...attribute.KeyValue) MeasurementOption {
cp := make([]attribute.KeyValue, len(attributes))
copy(cp, attributes)
return attrOpt{set: attribute.NewSet(cp...)}
}

Go使用log更优雅打印输出

有这样一种常见场景, 我在开发调试时,需要大量输出代码.

在开发完成后,不希望这些调试信息输出. 只打印我需要的必要信息

可以使用log库,可以设置输出级别,对于那些调试信息,使用log打印, 其他的需要正常输出的使用fmt