Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CONTRIBUTING.md #27

Merged
merged 9 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Contributing to Tyk

**First**: if you're unsure or afraid of anything, just ask or submit the issue or pull request anyway. You won't be yelled at for giving your best effort. The worst that can happen is that you'll be politely asked to change something. We appreciate any sort of contributions, and don't want a wall of rules to get in the way of that.
**First**: if you're unsure or afraid of anything, just ask or submit the issue or pull request anyway. You won't be yelled at for giving your best effort. The worst that can happen is that you'll be politely asked to change something. We appreciate any sort of contributions and don't want a wall of rules to get in the way of that.

However, for those individuals who want a bit more guidance on the best way to contribute to the project, read on. This document will cover what we're looking for. By addressing all the points we're looking for, it raises the chances we can quickly merge or address your contributions.

Expand All @@ -21,43 +21,60 @@ We do value the time each contributor spends contributing to this repo, and we w
Below we have outlined

### Filling an issue
Before opening an issue, ff you have a question about Tyk or have a problem using it, please
start with the GitHub search and our [community forum](https://community.tyk.io).
If that doesn't answer your questions, and you have an idea for a new capability or if you think you found a bug,[file an
If you have a question, a problem, or an idea for a new capability, or if you think you found a bug, please [create an
issue](/issues/new).

### Contributor License Agreements

Before we can accept any PR the contributor need to sign the [TYK CLA](./CLA.md).
Before we can accept any PR the contributor needs to sign the [TYK CLA](./CLA.md).

Once you are CLA'ed, we'll be able to accept your pull requests.For any issues that you face during this process, please create a GitHub issue explaining the problem, and we will help get it sorted out.
Once you are CLA'ed, we'll be able to accept your pull requests. For any issues that you face during this process, please create a GitHub issue explaining the problem, and we will help get it sorted out.

### Guidelines for Pull Requests
We have created a few guidelines to help with creating PR. To make sure these requirements are followed we added them to the PR form as well:

1. When working on an existing issue, simply respond to the issue and express interest in working on it. This helps other people know that the issue is active, and hopefully prevents duplicated efforts.
1. When working on an existing issue, simply respond to the issue and express interest in working on it. This helps other people know that the issue is active and hopefully prevents duplicated efforts.
2. For new ideas or breaking changes it is always better to open an issue and discuss your idea with our team first, before implementing it.
3. Create small Pull request that address a single issue instead of multiple issues at the same time. This will make it possible for the PRS to be reviewed independently.
3. Create a small Pull request that addresses a single issue instead of multiple issues at the same time. This will make it possible for the PRS to be reviewed independently.
5. Make sure to run tests locally before submitting a pull request and verify that all of them are passing.
6. Documentation - a new capability or improvement needs to be exposed in the form of documentation which needs to be created before this PR is merged. Please open a ticket in [Tyk docs repo](https://github.com/TykTechnologies/tyk-docs/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=) with all the relevant content and link it to the code PR. We are also happy work with you on creating docs so please let us know. Once the docs are ready and review has been done we can merge the PR
6. Documentation - a new capability or improvement needs to be exposed in the form of documentation which needs to be created before this PR is merged. Please open a ticket in [Tyk docs repo](https://github.com/TykTechnologies/tyk-docs/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=) with all the relevant content and link it to the code PR. We are also happy work with you on creating docs so please let us know. Once the docs are ready and the review has been done we can merge the PR
7. Tips for making sure we review your pull request faster :
1. Code is documented. Please comment the code where possible, especially for fields and functions.
1. Code is documented. Please comment on the code where possible, especially for fields and functions.
2. Use meaningful commit messages.
3. keep your pull request up to date with upstream master to avoid merge conflicts.
3. keep your pull request up to date with the upstream master to avoid merge conflicts.
4. Provide a good PR description as a record of what change is being made and why it was made. Link to a GitHub issue if it exists.
5. Tick all the relevant checkboxes in the PR form

### Project Structure
[sample project structure](https://github.com/getkin/kin-openapi/tree/0846d700650012c02a16668ebd2bf1e77e9a1669#structure)
1. *folder one(package one) - explain what is in this package and what code in this package does ...*
2. *folder one(package one) - explain what is in this package and what code in this package does ...*
3. *folder one(package one) - explain what is in this package and what code in this package does ...*

### Building and Running test
*explain to the contributor how there can build and run test cases for this project*

### Coding Conventions
*if your team has any coding conventions write them here*
We haven't yet published an official code convention guide or a linter. For now please keep the current conventions.

### Development Setup
To contribute, follow these steps:

1. Fork the repository on GitHub.
2. Clone your fork to your local machine:
```git
git clone https://github.com/your-username/struct-viewer.git
```

3. Create a new branch for your feature or bugfix:
```git
git checkout -b my-feature-branch
```

4. Make your changes and commit them with clear messages:
```git
git commit -m "Add new feature"
```

5. Push your changes to your fork:
```git
git push origin my-feature-branch
```

6. Submit a pull request to the main repository.


### Resources
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
Expand Down
74 changes: 53 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# struct_viewer

The struct_viewer package is a Go library that provides functionality for managing application configurations using Go struct types and environment variables. It allows you to define your configuration as a struct and easily populate it with values from environment variables
The struct_viewer package is a Go library designed to simplify the management and visualization of application configurations using Go structs and environment variables. It allows you to define your configuration as a struct, populate it with values from environment variables, and expose both the configuration and its corresponding environment variables via HTTP endpoints for easy inspection and debugging.

## Features

- Parse struct-based configurations.
- Expose configuration fields and environment variables as JSON.
- Simple HTTP handlers to expose config and envs.
- Secure: Automatically obfuscate sensitive data.

## Installation

To install the struct_viewer package, use the go get command:
To install the *struct_viewer* package, use the `go get` command:

```bash
go get -u github.com/TykTechnologies/struct-viewer
```

## Usage

Below is a simple example of how to use *struct_viewer* in your application:

```go
package main

Expand All @@ -23,31 +32,33 @@ import (
)

type Config struct {
ListenPort int `json:"listen_port"`
Debug bool `json:"debug"`
LogFile string `json:"log_file"`

Field1 string `json:"field1"`
Field2 int `json:"field2"`

// This field can be obfuscated with the structviewer tag
Field3secret string `json:"field3_secret" structviewer:"obfuscate"`
}

func main() {
config := &struct_viewer.Config{
Object: &Config{
ListenPort: 8080,
Debug: true,
LogFile: "/var/log/app.log",
},
Path: "./main.go",
ParseComments: true,
}

// Define configuration structure
config := &structviewer.Config{
Object: &YourConfigStruct{
Field1: "value1",
Field2: 123,
},

}

// prefix is added to each env var
v, err := structviewer.New(config, "APP_")
v, err := structviewer.New(config, "PREFIX")
if err != nil {
panic(err)
}

http.HandleFunc("/config", v.JSONHandler)
http.HandleFunc("/envs", v.EnvsHandler)
log.Println("Running server on port :8080")
err = http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
Expand All @@ -57,18 +68,39 @@ func main() {

This will expose two endpoints:

- `/config`: returns a json representation of the config struct
- `/envs`: returns a json representation of the environment variables of the config struct
- `/config`: returns a json representation of the config struct.
- Example: `curl -s 'http://localhost:8080/config' | jq .`
- `/envs`: returns a json representation of the environment variables of the config struct.
You can pass query parameters `env` to the endpoints to retrieve specific config fields or specific environment variables.
- Example:
- `curl -s 'http://localhost:8080/env' | jq .`
- `curl -s 'http://localhost:8080/env?env=PREFIX_FIELD1' | jq .`

## HTTP Handlers
`/config`: Exposes the entire config object.
`/detailed-config`: Exposes detailed configuration fields with descriptions.
`/envs`: Exposes environment variables mapped from the config object.


## Error Handling
The library provides several error types:

`ErrNilConfig`: Returned when a nil configuration struct is provided.
`ErrEmptyStruct`: Returned when an empty struct is provided.
`ErrInvalidObjectType`: Returned when the object is not of struct type.
## Contributing
We welcome contributions! Please see our contribution guidelines for details.


You can pass query parameters `field` or `env` to the endpoints to retrieve specific config fields or specific environment variables.

## Limitations

- Only exported fields in struct are parsed
- Only exported fields in Go struct are parsed
- Only struct fields can have comments in them
- Single file parsing
- No obfuscation

## Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on GitHub.
Contributing
We welcome contributions! Please see our [contribution guidelines](CONTRIBUTING.md) for details. If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on GitHub.
Loading