SCC to Go Viper

License

Package Go untuk mengambil konfigurasi aplikasi dari Spring Cloud Config Server dan langsung menyimpannya ke Viper untuk kemudahan akses di aplikasi Go.
✨ Fitur
- Fetch konfigurasi langsung dari Spring Cloud Config Server (/application/profile)
- Support authentication (username/password)
- Integrasi otomatis dengan Viper
- Mendukung format konfigurasi: YAML, JSON, Properties (auto mapping ke Viper)
- Cocok untuk aplikasi Go yang ingin pakai central config seperti Spring di ekosistem Java
🚀 Instalasi
go get -u github.com/KAnggara75/scc2go
🔧 Penggunaan
1. Import package
import (
"github.com/KAnggara75/scc2go"
)
2. Inisialisasi dan ambil konfigurasi
func init() {
scc2go.GetEnv(os.Getenv("SCC_URL"), os.Getenv("AUTH"))
}
3. Akses konfigurasi di Viper
package config
import (
"github.com/spf13/viper"
)
func GetDBConn() string {
return viper.GetString("db.myapp.host")
}
4. Contoh penggunaan
package main
import (
"fmt"
"os"
"github.com/KAnggara75/scc2go"
"github.com/spf13/viper"
)
func init() {
scc2go.GetEnv(os.Getenv("SCC_URL"), os.Getenv("AUTH"))
}
func main() {
deviceId := viper.GetString("db.myapp.host")
fmt.Println("Device ID:", deviceId)
}
📝 Konfigurasi yang Didukung
- Format: .yaml, .yml, .json, .properties
- Key mapping otomatis dari response Spring Cloud Config ke viper
🔒 Autentikasi
- Tambahkan field Auth jika server butuh basic auth.
scc2go.GetEnv("SCC_URL", "AUTH")
📦 Versioning
This project follows Semantic Versioning with automated releases based on Conventional Commits.
For detailed information about versioning and commit message format, see VERSIONING.md.
Quick Reference
feat: - New feature (minor version bump)
fix: - Bug fix (patch version bump)
feat!: or BREAKING CHANGE: - Breaking change (major version bump)
🧪 Testing
Run tests with coverage:
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
Current test coverage: 97.1%
🤝 Kontribusi
Pull request & masukan sangat diterima!
How to Contribute
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature)
- Commit your changes using Conventional Commits
feat: add new feature
fix: resolve bug
docs: update documentation
- Push to the branch (
git push origin feat/amazing-feature)
- Open a Pull Request
See VERSIONING.md for commit message guidelines.