ronantakizawa/codereview-bench huggingface dataset:
Repository: usememos/memos
File: server/router/api/v1/thumbnail.go (Go)

Code before:
		return nil, errors.Wrap(err, "failed to decode thumbnail image")
	}

	thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
	return thumbnailImage, nil
}

func (t Thumbnail) SaveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	dstDir := filepath.Dir(path)
	if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
		return errors.Wrap(err, "failed to create thumbnail directory")
	}

	if err := imaging.Save(thumbnailImage, path); err != nil {
		return errors.Wrap(err, "failed to save thumbnail file")
	}

	return nil
}

func (t Thumbnail) ImageToBlob(thumbnailImage image.Image) ([]byte, error) {
	mimeTypeMap := map[string]imaging.Format{
		"image/png":  imaging.JPEG,
		"image/jpeg": imaging.PNG,
	}

	imgFormat, ok := mimeTypeMap[t.resource.Type]
	if !ok {
		return nil, errors.New("failed to map resource type to an image encoder format")
	}

	buf := new(bytes.Buffer)
	if err := imaging.Encode(buf, thumbnailImage, imgFormat); err != nil {
		return nil, errors.Wrap(err, "failed to convert thumbnail image to bytes")
	}

	return buf.Bytes(), nil
}

func (t Thumbnail) DeleteFile(assetsFolderPath string) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	if _, err := os.Stat(path); err != nil {

Review comment (suggestion):
```suggestion
func (t *Thumbnail) ImageToBlob(thumbnailImage image.Image) ([]byte, error) {
```

Code after:
	src, err := imaging.Decode(reader, imaging.AutoOrientation(true))
	if err != nil {
		return nil, errors.Wrap(err, "failed to decode thumbnail image")
	}

	thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
	return thumbnailImage, nil
}

func (t *thumbnail) saveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	dstDir := filepath.Dir(path)
	if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
		return errors.Wrap(err, "failed to create thumbnail directory")
	}

	if err := imaging.Save(thumbnailImage, path); err != nil {
		return errors.Wrap(err, "failed to save thumbnail file")
	}

	return nil
}

func (t *thumbnail) imageToBlob(thumbnailImage image.Image) ([]byte, error) {
	mimeTypeMap := map[string]imaging.Format{
		"image/png":  imaging.JPEG,
		"image/jpeg": imaging.PNG,
	}

	imgFormat, ok := mimeTypeMap[t.resource.Type]
	if !ok {
		return nil, errors.New("failed to map resource type to an image encoder format")
	}

	buf := new(bytes.Buffer)
	if err := imaging.Encode(buf, thumbnailImage, imgFormat); err != nil {
		return nil, errors.Wrap(err, "failed to convert thumbnail image to bytes")
	}

	return buf.Bytes(), nil
}

func (t *thumbnail) deleteFile(assetsFolderPath string) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}
Repository: usememos/memos
File: server/router/api/v1/thumbnail.go (Go)

Code before:
	return dstBlob, nil
}

func GenerateThumbnailImage(sourceBlob []byte) (image.Image, error) {
	var availableGeneratorAmount int32 = 32

	if atomic.LoadInt32(&availableGeneratorAmount) <= 0 {
		return nil, errors.New("not enough available generator amount")
	}

	atomic.AddInt32(&availableGeneratorAmount, -1)
	defer func() {
		atomic.AddInt32(&availableGeneratorAmount, 1)
	}()

	reader := bytes.NewReader(sourceBlob)
	src, err := imaging.Decode(reader, imaging.AutoOrientation(true))
	if err != nil {
		return nil, errors.Wrap(err, "failed to decode thumbnail image")
	}

	thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
	return thumbnailImage, nil
}

func (t Thumbnail) SaveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	dstDir := filepath.Dir(path)
	if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
		return errors.Wrap(err, "failed to create thumbnail directory")
	}

	if err := imaging.Save(thumbnailImage, path); err != nil {
		return errors.Wrap(err, "failed to save thumbnail file")
	}

	return nil
}

func (t Thumbnail) ImageToBlob(thumbnailImage image.Image) ([]byte, error) {
	mimeTypeMap := map[string]imaging.Format{
		"image/png":  imaging.JPEG,
		"image/jpeg": imaging.PNG,
	}

	imgFormat, ok := mimeTypeMap[t.resource.Type]
	if !ok {

Review comment (suggestion):
```suggestion
func (t *Thumbnail) SaveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
```

Code after:
	}

	return dstBlob, nil
}

func (thumbnail) generateImage(sourceBlob []byte) (image.Image, error) {
	var availableGeneratorAmount int32 = 32

	if atomic.LoadInt32(&availableGeneratorAmount) <= 0 {
		return nil, errors.New("not enough available generator amount")
	}

	atomic.AddInt32(&availableGeneratorAmount, -1)
	defer func() {
		atomic.AddInt32(&availableGeneratorAmount, 1)
	}()

	reader := bytes.NewReader(sourceBlob)
	src, err := imaging.Decode(reader, imaging.AutoOrientation(true))
	if err != nil {
		return nil, errors.Wrap(err, "failed to decode thumbnail image")
	}

	thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
	return thumbnailImage, nil
}

func (t *thumbnail) saveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	dstDir := filepath.Dir(path)
	if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
		return errors.Wrap(err, "failed to create thumbnail directory")
	}

	if err := imaging.Save(thumbnailImage, path); err != nil {
		return errors.Wrap(err, "failed to save thumbnail file")
	}

	return nil
}

func (t *thumbnail) imageToBlob(thumbnailImage image.Image) ([]byte, error) {
	mimeTypeMap := map[string]imaging.Format{
		"image/png":  imaging.JPEG,
		"image/jpeg": imaging.PNG,
	}
Repository: usememos/memos
File: server/router/api/v1/thumbnail.go (Go)

Code before:
		return errors.Wrap(err, "failed to save thumbnail file")
	}

	return nil
}

func (t Thumbnail) ImageToBlob(thumbnailImage image.Image) ([]byte, error) {
	mimeTypeMap := map[string]imaging.Format{
		"image/png":  imaging.JPEG,
		"image/jpeg": imaging.PNG,
	}

	imgFormat, ok := mimeTypeMap[t.resource.Type]
	if !ok {
		return nil, errors.New("failed to map resource type to an image encoder format")
	}

	buf := new(bytes.Buffer)
	if err := imaging.Encode(buf, thumbnailImage, imgFormat); err != nil {
		return nil, errors.Wrap(err, "failed to convert thumbnail image to bytes")
	}

	return buf.Bytes(), nil
}

func (t Thumbnail) DeleteFile(assetsFolderPath string) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	if _, err := os.Stat(path); err != nil {
		if !errors.Is(err, os.ErrNotExist) {
			return errors.Wrap(err, "failed to check thumbnail image stat")
		}
	}

	if err := os.Remove(path); err != nil {
		return errors.Wrap(err, "failed to delete thumbnail file")
	}

	return nil
}


Review comment (suggestion):
```suggestion
func (t *Thumbnail) DeleteFile(assetsFolderPath string) error {
```

Code after:

	if err := imaging.Save(thumbnailImage, path); err != nil {
		return errors.Wrap(err, "failed to save thumbnail file")
	}

	return nil
}

func (t *thumbnail) imageToBlob(thumbnailImage image.Image) ([]byte, error) {
	mimeTypeMap := map[string]imaging.Format{
		"image/png":  imaging.JPEG,
		"image/jpeg": imaging.PNG,
	}

	imgFormat, ok := mimeTypeMap[t.resource.Type]
	if !ok {
		return nil, errors.New("failed to map resource type to an image encoder format")
	}

	buf := new(bytes.Buffer)
	if err := imaging.Encode(buf, thumbnailImage, imgFormat); err != nil {
		return nil, errors.Wrap(err, "failed to convert thumbnail image to bytes")
	}

	return buf.Bytes(), nil
}

func (t *thumbnail) deleteFile(assetsFolderPath string) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")
	}

	if _, err := os.Stat(path); err != nil {
		if !errors.Is(err, os.ErrNotExist) {
			return errors.Wrap(err, "failed to check thumbnail image stat")
		}
	}

	if err := os.Remove(path); err != nil {
		return errors.Wrap(err, "failed to delete thumbnail file")
	}

	return nil
}
Repository: usememos/memos
File: server/router/api/v1/thumbnail.go (Go)

Code before:
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return nil, errors.Wrap(err, "failed to get thumbnail file path")
	}

	if _, err := os.Stat(path); err != nil {
		if !errors.Is(err, os.ErrNotExist) {
			return nil, errors.Wrap(err, "failed to check thumbnail image stat")
		}
	}

	dstFile, err := os.Open(path)
	if err != nil {
		return nil, errors.Wrap(err, "failed to open thumbnail file")
	}
	defer dstFile.Close()

	dstBlob, err := io.ReadAll(dstFile)
	if err != nil {
		return nil, errors.Wrap(err, "failed to read thumbnail file")
	}

	return dstBlob, nil
}

func GenerateThumbnailImage(sourceBlob []byte) (image.Image, error) {
	var availableGeneratorAmount int32 = 32

	if atomic.LoadInt32(&availableGeneratorAmount) <= 0 {
		return nil, errors.New("not enough available generator amount")
	}

	atomic.AddInt32(&availableGeneratorAmount, -1)
	defer func() {
		atomic.AddInt32(&availableGeneratorAmount, 1)
	}()

	reader := bytes.NewReader(sourceBlob)
	src, err := imaging.Decode(reader, imaging.AutoOrientation(true))
	if err != nil {
		return nil, errors.Wrap(err, "failed to decode thumbnail image")
	}

	thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
	return thumbnailImage, nil
}

func (t Thumbnail) SaveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
	path, err := t.getFilePath(assetsFolderPath)
	if err != nil {
		return errors.Wrap(err, "failed to get thumbnail file path")

Review comment (suggestion):
If we don't use it in other package, it should be a camel naming case.

```suggestion
func generateThumbnailImage(sourceBlob []byte) (image.Image, error) {
```

Code after:
func (t *thumbnail) getFile(assetsFolderPath string) ([]byte, error) {
	path, err := t.getFilePath(assetsFolderPath)

	if err != nil {
		return nil, errors.Wrap(err, "failed to get thumbnail file path")
	}

	if _, err := os.Stat(path); err != nil {
		if !errors.Is(err, os.ErrNotExist) {
			return nil, errors.Wrap(err, "failed to check thumbnail image stat")
		}
	}

	dstFile, err := os.Open(path)
	if err != nil {
		return nil, errors.Wrap(err, "failed to open thumbnail file")
	}
	defer dstFile.Close()

	dstBlob, err := io.ReadAll(dstFile)
	if err != nil {
		return nil, errors.Wrap(err, "failed to read thumbnail file")
	}

	return dstBlob, nil
}

func (thumbnail) generateImage(sourceBlob []byte) (image.Image, error) {
	var availableGeneratorAmount int32 = 32

	if atomic.LoadInt32(&availableGeneratorAmount) <= 0 {
		return nil, errors.New("not enough available generator amount")
	}

	atomic.AddInt32(&availableGeneratorAmount, -1)
	defer func() {
		atomic.AddInt32(&availableGeneratorAmount, 1)
	}()

	reader := bytes.NewReader(sourceBlob)
	src, err := imaging.Decode(reader, imaging.AutoOrientation(true))
	if err != nil {
		return nil, errors.Wrap(err, "failed to decode thumbnail image")
	}

	thumbnailImage := imaging.Resize(src, 512, 0, imaging.Lanczos)
	return thumbnailImage, nil
}

func (t *thumbnail) saveAsFile(assetsFolderPath string, thumbnailImage image.Image) error {
	path, err := t.getFilePath(assetsFolderPath)
Repository: usememos/memos
File: web/src/components/MemoFilters.tsx (TypeScript)

Code before:
import { isEqual } from "lodash-es";
import { CalendarIcon, CheckCircleIcon, CodeIcon, EyeIcon, FilterIcon, LinkIcon, SearchIcon, TagIcon, XIcon } from "lucide-react";
import { useEffect } from "react";
import { useSearchParams } from "react-router-dom";
import { usePrevious } from "react-use";
import { FilterFactor, getMemoFilterKey, MemoFilter, parseFilterQuery, stringifyFilters, useMemoFilterStore } from "@/store/v1";

const MemoFilters = () => {
  const [searchParams, setSearchParams] = useSearchParams();
  const memoFilterStore = useMemoFilterStore();
  const filters = memoFilterStore.filters;
  const prevFilters = usePrevious(filters);
  const orderByTimeAsc = memoFilterStore.orderByTimeAsc;
  const prevOrderByTimeAsc = usePrevious(orderByTimeAsc);

  // Sync the filters and orderByTimeAsc to the search params.
  useEffect(() => {
    const newSearchParams = new URLSearchParams(searchParams);

    if (prevOrderByTimeAsc !== orderByTimeAsc) {
      if (orderByTimeAsc) {
        newSearchParams.set("orderBy", "asc");
      } else {
        newSearchParams.delete("orderBy");
      }
    }

    if (prevFilters && stringifyFilters(prevFilters) !== stringifyFilters(filters)) {
      if (filters.length > 0) {
        newSearchParams.set("filter", stringifyFilters(filters));

Review comment (suggestion):
```suggestion
import usePrevious from "react-use/lib/usePrevious";
```

Code after:
import { isEqual } from "lodash-es";
import { CalendarIcon, CheckCircleIcon, CodeIcon, EyeIcon, FilterIcon, LinkIcon, SearchIcon, TagIcon, XIcon } from "lucide-react";
import { useEffect } from "react";
import { useSearchParams } from "react-router-dom";
import usePrevious from "react-use/lib/usePrevious";
import { FilterFactor, getMemoFilterKey, MemoFilter, parseFilterQuery, stringifyFilters, useMemoFilterStore } from "@/store/v1";

const MemoFilters = () => {
  const [searchParams, setSearchParams] = useSearchParams();
  const memoFilterStore = useMemoFilterStore();
  const filters = memoFilterStore.filters;
  const prevFilters = usePrevious(filters);
  const orderByTimeAsc = memoFilterStore.orderByTimeAsc;
  const prevOrderByTimeAsc = usePrevious(orderByTimeAsc);

  // Sync the filters and orderByTimeAsc to the search params.
  useEffect(() => {
    const newSearchParams = new URLSearchParams(searchParams);

    if (prevOrderByTimeAsc !== orderByTimeAsc) {
      if (orderByTimeAsc) {
        newSearchParams.set("orderBy", "asc");
      } else {
        newSearchParams.delete("orderBy");
      }
    }

    if (prevFilters && stringifyFilters(prevFilters) !== stringifyFilters(filters)) {
      if (filters.length > 0) {
        newSearchParams.set("filter", stringifyFilters(filters));
Repository: utmapp/UTM
File: Configuration/UTMConfigurable.h (C/C++)

Code before:
//

#import <Foundation/Foundation.h>
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#define PlatformColor NSColor
#else
#import <UIKit/UIKit.h>
#define PlatformColor UIColor
#endif

NS_ASSUME_NONNULL_BEGIN

@protocol UTMConfigurable

@property (nonatomic, copy) NSString *name;
@property (nonatomic, nullable, readonly) NSURL *iconUrl;
@property (nonatomic, nullable, copy) NSURL *selectedCustomIconPath;
@property (nonatomic, nullable, copy) NSString *icon;
@property (nonatomic, assign) BOOL iconCustom;
@property (nonatomic, nullable, copy) NSString *notes;

@property (nonatomic, nullable, copy) NSString *consoleTheme;
// TODO: Maybe use CGColor (But hard to handle)
@property (nonatomic, nullable, copy) PlatformColor *consoleTextColor;
@property (nonatomic, nullable, copy) PlatformColor *consoleBackgroundColor;
@property (nonatomic, nullable, copy) NSString *consoleFont;
@property (nonatomic, nullable, copy) NSNumber *consoleFontSize;
@property (nonatomic, assign) BOOL consoleCursorBlink;
@property (nonatomic, nullable, copy) NSString *consoleResizeCommand;

@property (nonatomic, readonly, assign) BOOL isAppleVirtualization;

@end

NS_ASSUME_NONNULL_END


Review comment (suggestion):
I was thinking maybe using a `CGColor` might be a good idea for two reasons:
- SwiftUI's `ColorPicker` can take a binding to a `CGColor`
- It would be compatible with both platforms, the `PlatformColor` stuff wouldn't be needed

But the problem is that `CGColor` isn't an object, so passing it around is harder. And also I'm not sure if `CGColor` can be used with a keyed archiver to save it.

I think it wouldn't be worth the extra trouble, since it isn't that much code in the `Binding` that converts a `NSColor` to the SwiftUI `Color` type.

Code after:
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol UTMConfigurable

@property (nonatomic, assign) BOOL isRenameDisabled;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, nullable, readonly) NSURL *iconUrl;
@property (nonatomic, nullable, copy) NSURL *selectedCustomIconPath;
@property (nonatomic, nullable, copy) NSString *icon;
@property (nonatomic, assign) BOOL iconCustom;
@property (nonatomic, nullable, copy) NSString *notes;

@property (nonatomic, nullable, copy) NSString *consoleTheme;
@property (nonatomic, nullable, copy) NSString *consoleTextColor;
@property (nonatomic, nullable, copy) NSString *consoleBackgroundColor;
@property (nonatomic, nullable, copy) NSString *consoleFont;
@property (nonatomic, nullable, copy) NSNumber *consoleFontSize;
@property (nonatomic, assign) BOOL consoleCursorBlink;
@property (nonatomic, nullable, copy) NSString *consoleResizeCommand;

@property (nonatomic, readonly, assign) BOOL isAppleVirtualization;

@end

NS_ASSUME_NONNULL_END
Repository: v2fly/v2ray-core
File: app/dns/nameserver_doh.go (Go)

Code before:
	if option.IPv6Enable && record.AAAA != nil && record.AAAA.RCode == dnsmessage.RCodeSuccess {
		aaaa, err := record.AAAA.getIPs()
		if err != nil {
			lastErr = err
		}
		ips = append(ips, aaaa...)
	}

	if option.IPv4Enable && record.A != nil && record.A.RCode == dnsmessage.RCodeSuccess {
		a, err := record.A.getIPs()
		if err != nil {
			lastErr = err
		}
		ips = append(ips, a...)
	}

	if len(ips) > 0 {
		return toNetIP(ips)
	}

	if lastErr != nil {
		return nil, lastErr
	}

	if (option.IPv4Enable && record.A != nil) || (option.IPv6Enable && record.AAAA != nil) {
		return nil, dns_feature.ErrEmptyResponse
	}

	return nil, errRecordNotFound
}

// QueryIP implements Server.
func (s *DoHNameServer) QueryIP(ctx context.Context, domain string, clientIP net.IP, option dns_feature.IPOption, disableCache bool) ([]net.IP, error) { // nolint: dupl
	fqdn := Fqdn(domain)

	if disableCache {
		newError("DNS cache is disabled. Querying IP for ", domain, " at ", s.name).AtDebug().WriteToLog()
	} else {
		ips, err := s.findIPsForDomain(fqdn, option)
		if err != errRecordNotFound {
			newError(s.name, " cache HIT ", domain, " -> ", ips).Base(err).AtDebug().WriteToLog()
			return ips, err
		}
	}

	// ipv4 and ipv6 belong to different subscription groups
	var sub4, sub6 *pubsub.Subscriber
	if option.IPv4Enable {
		sub4 = s.pub.Subscribe(fqdn + "4")
		defer sub4.Close()
	}

Review comment (bug):
I found a bug that might caused by this changes. The program may wait until the context timeout if the records are empty, and return this error:
```
[Info] app/dns: failed to lookup ip for domain api.twitter.com at server DOH//9.9.9.9 > context deadline exceeded
[Info] proxy/dns: ip query > app/dns: returning nil for domain api.twitter.com > multierr: context deadline exceeded |
```

c.c. @Loyalsoldier 

Code after:

	var err4 error
	var err6 error
	var ips []net.Address
	var ip6 []net.Address

	switch {
	case option.IPv4Enable:
		ips, err4 = record.A.getIPs()
		fallthrough
	case option.IPv6Enable:
		ip6, err6 = record.AAAA.getIPs()
		ips = append(ips, ip6...)
	}

	if len(ips) > 0 {
		return toNetIP(ips)
	}

	if err4 != nil {
		return nil, err4
	}

	if err6 != nil {
		return nil, err6
	}

	return nil, errRecordNotFound
}

// QueryIP implements Server.
func (s *DoHNameServer) QueryIP(ctx context.Context, domain string, clientIP net.IP, option dns_feature.IPOption, disableCache bool) ([]net.IP, error) { // nolint: dupl
	fqdn := Fqdn(domain)

	if disableCache {
		newError("DNS cache is disabled. Querying IP for ", domain, " at ", s.name).AtDebug().WriteToLog()
	} else {
		ips, err := s.findIPsForDomain(fqdn, option)
		if err != errRecordNotFound {
			newError(s.name, " cache HIT ", domain, " -> ", ips).Base(err).AtDebug().WriteToLog()
			return ips, err
		}
	}

	// ipv4 and ipv6 belong to different subscription groups
	var sub4, sub6 *pubsub.Subscriber
	if option.IPv4Enable {
		sub4 = s.pub.Subscribe(fqdn + "4")
		defer sub4.Close()
	}
	if option.IPv6Enable {
Repository: v2fly/v2ray-core
File: infra/conf/transport_internet.go (Go)

Code before:
	}
}

type SocketConfig struct {
	Mark                 uint32 `json:"mark"`
	TFO                  *bool  `json:"tcpFastOpen"`
	TFOQueueLength       uint32 `json:"tcpFastOpenQueueLength"`
	TProxy               string `json:"tproxy"`
	AcceptProxyProtocol  bool   `json:"acceptProxyProtocol"`
	TCPKeepAliveInterval int32  `json:"tcpKeepAliveInterval"`
}

// Build implements Buildable.
func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
	var tfoSettings internet.SocketConfig_TCPFastOpenState
	if c.TFO != nil {
		if *c.TFO {
			tfoSettings = internet.SocketConfig_Enable
		} else {
			tfoSettings = internet.SocketConfig_Disable
		}
	}

	tfoQueueLength := c.TFOQueueLength
	if tfoQueueLength == 0 {
		tfoQueueLength = 1
	}

	var tproxy internet.SocketConfig_TProxyMode
	switch strings.ToLower(c.TProxy) {
	case "tproxy":
		tproxy = internet.SocketConfig_TProxy
	case "redirect":
		tproxy = internet.SocketConfig_Redirect
	default:
		tproxy = internet.SocketConfig_Off
	}

	return &internet.SocketConfig{
		Mark:                 c.Mark,
		Tfo:                  tfoSettings,
		TfoQueueLength:       tfoQueueLength,
		Tproxy:               tproxy,
		AcceptProxyProtocol:  c.AcceptProxyProtocol,
		TcpKeepAliveInterval: c.TCPKeepAliveInterval,
	}, nil
}

type StreamConfig struct {
	Network        *TransportProtocol  `json:"network"`
	Security       string              `json:"security"`

Review comment (suggestion):
On Linux, Go by default uses `/proc/sys/net/core/somaxconn` as the listener backlog, which is 4096 on my system. I recommend setting the default TFO queue length to 4096 to match the default listener backlog.

Code after:
	}
}

type SocketConfig struct {
	Mark                 uint32 `json:"mark"`
	TFO                  *bool  `json:"tcpFastOpen"`
	TFOQueueLength       uint32 `json:"tcpFastOpenQueueLength"`
	TProxy               string `json:"tproxy"`
	AcceptProxyProtocol  bool   `json:"acceptProxyProtocol"`
	TCPKeepAliveInterval int32  `json:"tcpKeepAliveInterval"`
}

// Build implements Buildable.
func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
	var tfoSettings internet.SocketConfig_TCPFastOpenState
	if c.TFO != nil {
		if *c.TFO {
			tfoSettings = internet.SocketConfig_Enable
		} else {
			tfoSettings = internet.SocketConfig_Disable
		}
	}

	tfoQueueLength := c.TFOQueueLength
	if tfoQueueLength == 0 {
		tfoQueueLength = 4096
	}

	var tproxy internet.SocketConfig_TProxyMode
	switch strings.ToLower(c.TProxy) {
	case "tproxy":
		tproxy = internet.SocketConfig_TProxy
	case "redirect":
		tproxy = internet.SocketConfig_Redirect
	default:
		tproxy = internet.SocketConfig_Off
	}

	return &internet.SocketConfig{
		Mark:                 c.Mark,
		Tfo:                  tfoSettings,
		TfoQueueLength:       tfoQueueLength,
		Tproxy:               tproxy,
		AcceptProxyProtocol:  c.AcceptProxyProtocol,
		TcpKeepAliveInterval: c.TCPKeepAliveInterval,
	}, nil
}

type StreamConfig struct {
	Network        *TransportProtocol  `json:"network"`
	Security       string              `json:"security"`