Browse Source

更新 'README.md'

tags/v1.3.2
梁 致源 3 years ago
parent
commit
3ab4c71a58
1 changed files with 9 additions and 19 deletions
  1. +9
    -19
      README.md

+ 9
- 19
README.md View File

@@ -4,35 +4,25 @@ cast
[![Build Status](https://api.travis-ci.org/spf13/cast.svg?branch=master)](https://travis-ci.org/spf13/cast)
[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/cast)](https://goreportcard.com/report/github.com/spf13/cast)

Easy and safe casting from one type to another in Go
在Go中轻松安全地从一种类型转换为另一种类型

Don’t Panic! ... Cast

## What is Cast?

Cast is a library to convert between different go types in a consistent and easy way.
Cast是一个库,用于以一致且简单的方式在不同的go类型之间进行转换。

Cast provides simple functions to easily convert a number to a string, an
interface into a bool, etc. Cast does this intelligently when an obvious
conversion is possible. It doesn’t make any attempts to guess what you meant,
for example you can only convert a string to an int when it is a string
representation of an int such as “8”. Cast was developed for use in
[Hugo](http://hugo.spf13.com), a website engine which uses YAML, TOML or JSON
for meta data.
Cast提供简单的功能,可轻松将数字转换为字符串,进入布尔等接口。当明显转换是可能的。 它不会尝试猜测您的意思,例如,您只能在字符串为字符串时将其转换为int
int的表示形式,例如“ 8”。 Cast的开发目的是用于[Hugo](http://hugo.spf13.com), 使用YAML,TOML或JSON的网站引擎用于元数据。

## Why use Cast?

When working with dynamic data in Go you often need to cast or convert the data
from one type into another. Cast goes beyond just using type assertion (though
it uses that when possible) to provide a very straightforward and convenient
library.
在Go中使用动态数据时,您通常需要强制转换或转换数据
从一种类型变成另一种类型。 强制转换不仅限于使用类型断言(尽管
它在可能的情况下使用它)来提供非常直接和方便的库。

If you are working with interfaces to handle things like dynamic content
you’ll need an easy way to convert an interface into a given type. This
is the library for you.

If you are taking in data from YAML, TOML or JSON or other formats which lack
full types, then Cast is the library for you.
如果您正在使用接口来处理诸如动态内容之类的内容您将需要一种简单的方法来将接口转换为给定类型。 这个是您的库。
如果您要从YAML,TOML或JSON或其他缺少格式的数据中获取数据完整类型,那么Cast是适合您的库。

## Usage



Loading…
Cancel
Save