Skip to content

Commit

Permalink
documentation is done and making v0.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Jan 23, 2016
1 parent bc34938 commit 4d51320
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Robust & Easy to use model mapper and model utility methods for Go. Typical meth
go-model tested with Go `v1.2` and above.

## Features
go-model provides handy methods to process struct with below highlighted features. It's born from typical need while developing Go application or utility. I hope it's helpful!
go-model provides handy methods (`Copy`, `Map`, `IsZero`, etc.) to process struct with below highlighted features. It's born from typical need while developing Go application or utility. I hope it's helpful!
* Embedded/Anonymous struct
* Multi-level nested struct/map/slice
* Pointer and non-pointer within struct/map/slice
Expand Down Expand Up @@ -47,10 +47,9 @@ import (
* RemoveNoTraverseType - [usage](#addnotraversetype--removenotraversetype-methods), [godoc](https://godoc.org/github.com/jeevatkm/go-model#RemoveNoTraverseType)

#### Copy Method
How do I copy my struct object into another? Not to worry go-model does deep copy.
How do I copy my struct object into another? Not to worry, go-model does deep copy.
```go
// let's say you have just decoded/unmarshalled your request body into object
// may be intermediate struct 'TempProduct' for parsing user input
// let's say you have just decoded/unmarshalled your request body to struct object.
tempProduct, _ := myapp.ParseJSON(request.Body)

product := Product{}
Expand All @@ -66,7 +65,7 @@ fmt.Printf("\nDestination: %#v\n", product)
```

#### Map Method
I want to convert my struct into Map (`map[string]interface{}`). Not to worry go-model does deep convert.
I want to convert my struct into Map (`map[string]interface{}`). Not to worry, go-model does deep convert.
```go
// tag your SearchResult fields with appropriate options like
// -, name, omitempty, notraverse to get desired result.
Expand All @@ -79,9 +78,9 @@ fmt.Printf("\nSearch Result Map: %#v\n", srchResMap)
```

#### IsZero Method
I want to check my struct object is empty or not. Not to worry go-model does deep zero check.
I want to check my struct object is empty or not. Not to worry, go-model does deep zero check.
```go
// let's you have just decoded/unmarshalled your request body into object
// let's say you have just decoded/unmarshalled your request body to struct object.
productInfo, _ := myapp.ParseJSON(request.Body)

// wanna check productInfo is empty or not
Expand All @@ -93,11 +92,11 @@ fmt.Println("Hey, I have zero values:", isEmpty)
```

#### AddNoTraverseType & RemoveNoTraverseType Methods
There are scenarios, you want object values but not to traverse/look inside the struct object. Use `notraverse` option in the model tag for those fieds or Add it `NoTraverseTypeList`. Customize it as per your need.
There are scenarios, where you want the object values but not to traverse/look inside the struct object. Use `notraverse` option in the model tag for those fields or Add it `NoTraverseTypeList`. Customize it as per your need.

Default `NoTraverseTypeList` has these types `time.Time{}`, `&time.Time{}`, `os.File{}`, `&os.File{}`, `http.Request{}`, `&http.Request{}`, `http.Response{}`, `&http.Response{}`.
```go
// If you have added your type into list then you no need to mention `notraverse` option for those types.
// If you have added your type into list then you need not mention `notraverse` option for those types.

// Adding type into NoTraverseTypeList
model.AddNoTraverseType(time.Location{}, &time.Location{})
Expand All @@ -109,10 +108,10 @@ model.RemoveNoTraverseType(time.Location{}, &time.Location{})
## Versioning
go-model releases versions according to [Semantic Versioning](http://semver.org)

`gopkg.in/jeevatkm/go-model.vX` points to appropriate tag versions; `X` denotes version number and it's a stable release. It's recommended to use version, for eg. `gopkg.in/jeevatkm/go-model.v0`. Development takes place at the master branch. Althought the code in master should always compile and test successfully, it might break API's. We aim to maintain backwards compatibility, but API's and behaviour might be changed to fix a bug.
`gopkg.in/jeevatkm/go-model.vX` points to appropriate tag versions; `X` denotes version number and it's a stable release. It's recommended to use version, for eg. `gopkg.in/jeevatkm/go-model.v0`. Development takes place at the master branch. Although the code in master should always compile and test successfully, it might break API's. We aim to maintain backwards compatibility, but API's and behaviour might be changed to fix a bug.

## Contributing
Welcome! If you find any improvement or issue you want to fix. Feel free to send a pull request, I like pull requests that include tests case for fix/enhancement. Did my best to bring pretty good code coverage and feel free to write tests.
Welcome! If you find any improvement or issue you want to fix, feel free to send a pull request. I like pull requests that include test cases for fix/enhancement. I have done my best to bring pretty good code coverage. Feel free to write tests.

BTW, I'd like to know what you think about go-model. Kindly open an issue or send me an email; it'd mean a lot to me.

Expand Down
20 changes: 10 additions & 10 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func IsZero(s interface{}) bool {
//
// Example:
//
// src := SampleStruct{ /* source struct field values goes here */ }
// dst := SampleStruct{}
// src := SampleStruct { /* source struct field values go here */ }
// dst := SampleStruct {}
//
// errs := model.Copy(&dst, src)
// if errs != nil {
Expand All @@ -166,7 +166,7 @@ func IsZero(s interface{}) bool {
// Note:
// [1] Copy process continues regardless of the case it qualifies or not. The non-qualified field(s)
// gets added to '[]error' that you will get at the end.
// [2] Two dimensional slice type is not yet supported.
// [2] Two dimensional slice type is not supported yet.
//
// A "model" tag with the value of "-" is ignored by library for processing.
// Example:
Expand Down Expand Up @@ -220,23 +220,23 @@ func Copy(dst, src interface{}) []error {
return nil
}

// Map method converts all the exported field values from given struct into `map[string]interface{}`.
// Where the keys of the map are the field names and the values of the map is associated
// Map method converts all the exported field values from the given struct into `map[string]interface{}`.
// In which the keys of the map are the field names and the values of the map are the associated
// values of the field.
//
// Example:
//
// src := SampleStruct{ /* source struct field values goes here */ }
// src := SampleStruct { /* source struct field values go here */ }
//
// err := model.Map(src)
// if err != nil {
// fmt.Println("Error:", err)
// }
//
// Note:
// [1] Two dimensional slice type is not yet supported.
// [1] Two dimensional slice type is not supported yet.
//
// The default 'Key Name' string is the struct field name. However, can be
// The default 'Key Name' string is the struct field name. However, it can be
// changed in the struct field's tag value via "model" tag.
// Example:
//
Expand All @@ -251,7 +251,7 @@ func Copy(dst, src interface{}) []error {
// BookCode string `model:"-"`
//
// A "model" tag value with the option of "omitempty"; library will not include those values
// while converting into map[string]interface{}. If it's empty/zero value.
// while converting to map[string]interface{}. If it's empty/zero value.
// Example:
//
// // Field is not included in result map if it's empty/zero value
Expand All @@ -260,7 +260,7 @@ func Copy(dst, src interface{}) []error {
//
// A "model" tag value with the option of "notraverse"; library will not traverse
// inside the struct object. However, the field value will be evaluated whether
// it's zero value or not then accordingly added to the result map.
// it's zero value or not, and then added to the result map accordingly.
// Example:
//
// // Field is not traversed but value is evaluated/processed
Expand Down

0 comments on commit 4d51320

Please sign in to comment.