Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

`formatgo` is a Go package that provides utilities for formatting Go source code

License

NotificationsYou must be signed in to change notification settings

yyle88/formatgo

Repository files navigation

GitHub Workflow Status (branch)GoDocCoverage StatusSupported Go VersionsGitHub ReleaseGo Report Card

formatgo

formatgo is a Go package that provides utilities for formatting Go source code, whether it's in a byte slice, string, or a file, and even for entire directories containing Go files.

CHINESE README

中文说明

Installation

To install theformatgo package, you can run the following command:

go get github.com/yyle88/formatgo

Usage

The package provides several functions for formatting Go code. Below are the main functions that you can use:

FormatBytes

Formats Go source code from a byte slice.

formattedCode,err:=formatgo.FormatBytes(code []byte)
  • code: The source code as a byte slice.
  • Returns the formatted code as a byte slice or an error if something goes wrong.

FormatCode

Formats Go source code from a string.

formattedCode,err:= formatgo.FormatCode(codestring)
  • code: The source code as a string.
  • Returns the formatted code as a string or an error if something goes wrong.

FormatFile

Formats a Go source code file at the given path.

err:= formatgo.FormatFile(pathstring)
  • path: The path to the Go source code file.
  • Returns an error if the formatting fails.

FormatRoot

Formats all Go source files in the specified root directory and its subdirectories.

err:= formatgo.FormatRoot(rootstring)
  • root: The root directory to start formatting files from.
  • Returns an error if something goes wrong during the formatting process.

Example

Here’s a simple example of how to format Go code from a string:

package mainimport ("fmt""github.com/yyle88/formatgo")funcmain() {code:=`package mainimport "fmt"func main() {fmt.Println("Hello, world!")}`formattedCode,err:=formatgo.FormatCode(code)iferr!=nil {fmt.Println("Error formatting code:",err)return}fmt.Println("Formatted Code:",formattedCode)}

License

formatgo is open-source and released under the MIT License. See the LICENSE file for more information.


Support

Welcome to contribute to this project by submitting pull requests or reporting issues.

If you find this package helpful, give it a star on GitHub!

Thank you for your support!

Happy Coding withformatgo! 🎉

Give me stars. Thank you!!!

Starring

starring

About

`formatgo` is a Go package that provides utilities for formatting Go source code

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp