Skip to content

Commit

Permalink
add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
uanhi committed Jul 27, 2024
1 parent 8a47b70 commit a0b9287
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# server
apiport = :8080
_apiport = :8080

# database
user = root
password = "12345678"

# qwe


host = 127.0.0.1
port = 3306

Expand Down
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# dotenv

A Go language parsing tool for key value pair configuration files.

Used in configuration file parsing of back-end small applications. Only the following features are supported, please consider using them.

### grammar

This tool parses by line, where one line can be a key value, a comment, or a blank line.

```
_id=20
name = "Kate"
# Comment
```

- Keys can be uppercase and lowercase English letters and underscores.
- The equal sign cannot be missing.
- Values are parsed as strings by default, and single and double quotes are automatically ignored.

### value types

Structure unmarshalling of the following value types is supported.

```go
string
int | int8 | int16 | int32 | int64
uint | uint8 | uint16 | uint32 | uint64
float32 | float64
```

### install

```
go get github.com/bingxio/dotenv
```

### example

See: [parser_test.go](https://github.com/bingxio/dotenv/blob/main/parser_test.go)
5 changes: 3 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ func unmarshal() (KvSlice, error) {
if whiteSpace(); ip >= len(buffer) {
return slice, nil
}
if markComment(); ip >= len(buffer) {
return slice, nil
if now() == '#' {
markComment()
continue
}
v, err := markKeyValue()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
)

type Config struct {
ApiPort string
ApiPort string `env:"_apiport"`
User string
Password string
Host string
Port int
Port uint
Db string `env:"db_name"`
}

Expand Down

0 comments on commit a0b9287

Please sign in to comment.