added in License

This commit is contained in:
Ankit Patial 2024-11-18 20:53:13 +05:30
parent 9d40c9d7ec
commit a2739dbbcd
38 changed files with 222 additions and 39 deletions

27
LICENSE Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2024 Patial Tech. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Patial Tech. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,3 +1,6 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main package main
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package handler package handler
import ( import (
@ -31,7 +35,7 @@ func Request() func(http.Handler) http.Handler {
// ID // ID
requestID := r.Header.Get("X-Request-Id") requestID := r.Header.Get("X-Request-Id")
if requestID == "" { if requestID == "" {
requestID = uid.ULID() requestID = uid.NewUUID()
} }
ctx = context.WithValue(ctx, RequestIDKey, requestID) ctx = context.WithValue(ctx, RequestIDKey, requestID)

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main package main
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package config package config
import ( import (

View File

@ -11,7 +11,7 @@ import (
) )
// //
// copied from https://github.com/joho/godotenv/blob/main/parser.go // ported from https://github.com/joho/godotenv/blob/main/parser.go
// //
const ( const (

View File

@ -10,7 +10,7 @@ import (
) )
// //
// copied from https://github.com/joho/godotenv/blob/main/godotenv.go // ported from https://github.com/joho/godotenv/blob/main/godotenv.go
// //
// Read all env (with same file loading semantics as Load) but return values as // Read all env (with same file loading semantics as Load) but return values as

View File

@ -9,7 +9,7 @@ import (
) )
// //
// copied from https://github.com/joho/godotenv/blob/main/godotenv.go // ported from https://github.com/joho/godotenv/blob/main/godotenv.go
// //
const doubleQuoteSpecialChars = "\\\n\r\"!$`" const doubleQuoteSpecialChars = "\\\n\r\"!$`"

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package config package config
import "fmt" import "fmt"

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package db package db
import ( import (
@ -54,48 +58,52 @@ func Client() *ent.Client {
return cl return cl
} }
type entity interface {
GetID() (int64, error)
}
// A AuditHook is an example for audit-log hook. // A AuditHook is an example for audit-log hook.
func AuditHook(next ent.Mutator) ent.Mutator { func AuditHook(next ent.Mutator) ent.Mutator {
type Entity interface {
GetID() (int64, error)
}
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (v ent.Value, err error) { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (v ent.Value, err error) {
var id int64
start := time.Now() start := time.Now()
defer func() { defer func() {
saveAudit(ctx, id, m.Type(), m.Op().String(), time.Since(start), err) saveAudit(ctx, m.Type(), m.Op(), v, err, time.Since(start))
}() }()
v, err = next.Mutate(ctx, m) v, err = next.Mutate(ctx, m)
if en, ok := v.(Entity); ok {
id, _ = en.GetID()
}
logger.Info("** %v", v)
return return
}) })
} }
func saveAudit(_ context.Context, entID int64, entT, op string, d time.Duration, err error) { func saveAudit(ctx context.Context, t string, op ent.Op, v ent.Value, err error, d time.Duration) {
logger.Info("audit: %d, %s, %s, %s, %v", entID, entT, op, d, err) if t == "Audit" {
// ml.SetCreatedAt(time.Now()) // skip Audit table operations
// if usr := auth.CtxUser(ctx); usr != nil { return
// ml.SetByID(usr.ID) }
// ml.SetBy(usr.DisplayName)
// }
// switch op := m.Op(); { var entOp string
// case op.Is(ent.OpCreate): switch {
// ml.SetOperation("Create") case op.Is(ent.OpCreate):
entOp = "Create"
case op.Is(ent.OpDelete):
entOp = "Delete"
case op.Is(ent.OpDeleteOne):
entOp = "DeleteOne"
case op.Is(ent.OpUpdate):
entOp = "Update"
case op.Is(ent.OpUpdateOne):
entOp = "UpdateOne"
}
// case op.Is(ent.OpUpdate): big.
// ml.SetOperation("Update") reqID := ctx.Value("RequestID")
// case op.Is(ent.OpUpdateOne): ip := ctx.Value("RequestIP")
// ml.SetOperation("UpdateOne") ua := ctx.Value("RequestUA")
// case op.Is(ent.OpDelete): if en, ok := v.(entity); ok {
// ml.SetOperation("Delete") id, _ := en.GetID()
// case op.Is(ent.OpDeleteOne): logger.Info("%s %s %s-%s(%d) ip=%s ua=%s t=%v error=%e", reqID, status, op.String(), t, id, ip, ua, d, err)
// ml.SetOperation("DeleteOne") } else {
// } logger.Info("%s %s %s-%s ip=%s ua=%s t=%v error=%e", reqID, status, op.String(), t, ip, ua, d, err)
}
} }

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package migrations package migrations
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mailer package mailer
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package message package message
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package message package message
import _ "embed" import _ "embed"

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mailer package mailer
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
// EmailResetPWD link to user to reset password // EmailResetPWD link to user to reset password

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user package user
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package crypto package crypto
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package crypto package crypto
import "testing" import "testing"

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logger package logger
import ( import (

View File

@ -1,5 +1,9 @@
//go:build darwin //go:build darwin
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package open package open
import ( import (

View File

@ -1,5 +1,9 @@
//go:build linux //go:build linux
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package open package open
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package open package open
// WithDefaultApp open a file, directory, or URI using the OS's default application for that object type. // WithDefaultApp open a file, directory, or URI using the OS's default application for that object type.

View File

@ -1,5 +1,9 @@
//go:build windows //go:build windows
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package open package open
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package structs package structs
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uid package uid
import "github.com/sqids/sqids-go" import "github.com/sqids/sqids-go"

23
util/uid/uuid.go Normal file
View File

@ -0,0 +1,23 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uid
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
"gitserver.in/patialtech/rano/util/logger"
)
func NewUUID() string {
id, err := uuid.NewV7()
if err != nil {
logger.Incident(context.Background(), "New UUID", err.Error())
return fmt.Sprintf("%d", time.Now().UTC().UnixNano())
}
return id.String()
}

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package validate package validate
import ( import (

View File

@ -1,3 +1,7 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import { gql } from '@urql/svelte'; import { gql } from '@urql/svelte';
export const Me = gql` export const Me = gql`
query Me { query Me {

View File

@ -1,8 +1,12 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import { Client, cacheExchange, fetchExchange } from '@urql/svelte'; import { Client, cacheExchange, fetchExchange } from '@urql/svelte';
export function newClient(url: string) { export function newClient(url: string) {
return new Client({ return new Client({
url, url,
exchanges: [ fetchExchange] exchanges: [fetchExchange]
}); });
} }

View File

@ -0,0 +1,3 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

View File

@ -1 +1,5 @@
// Copyright 2024 Patial Tech. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
export let authUser = $state(); export let authUser = $state();

View File

@ -1,12 +1,15 @@
<script lang="ts"> <script lang="ts">
import { type Snippet } from "svelte"; import { type Snippet } from 'svelte';
interface Props { interface Props {
children: Snippet children: Snippet;
} }
const { children }:Props = $props(); const { children }: Props = $props();
</script> </script>
// Copyright 2024 Patial Tech. All rights reserved. // Use of this source code is governed by a BSD-style // license
that can be found in the LICENSE file.
<button> <button>
{@render children()} {@render children()}
</button> </button>