1. inisialisasi backend golang
This commit is contained in:
27
backend/certificate/private.pem
Normal file
27
backend/certificate/private.pem
Normal file
@@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEA0/SwlbdZPv2xMsuJUx3gcjqpHVTbqn1C79skaDqx1ewNblsB
|
||||
ZnLVPTytA2XhSizHe63XIxivZxL0JPhL5F3aX/5pMMBtPURYMuGk2lBxmvzJ+RFg
|
||||
D8VeIGER51byWXEESGZZ6azu5mectW9/QO9RnToWUDLiZwR3w+1z1b2/spB2pQtM
|
||||
obp9oD+iw/plh4TR4Pvdke1xATes1G4zKbQoL261P8yXxQLVLZxB9aUWzIXvqVwW
|
||||
kzd09nHSYprn6hCA9BA0Ev46a79MKd0JvMokQKXl0CyAQ/QPAXs/3S7Jabd7CKkd
|
||||
Zb1qz9Vo/sqVllMyUDruJTEQq3MMlYnQCCxPXQIDAQABAoIBAA6riO1T22F4vaL+
|
||||
Y2rVTouZc8sL7IhIUzG2wTZVmalsxSE2O0qT+B5c7LyneIhhwQzWY2WSd9FyhmNo
|
||||
rBgKRusN+MnfB7CN4mzjIT3bA4HurSwH/9YXmwQys8KHSg7Wu60nKGH8Diz0Tuxf
|
||||
4zbjWYrAUnsKipEGxiNRdAr/Lx10sgH//FxtBzGleb+4N0dsSDUsWa0ZWrrGjIAg
|
||||
o8LFXHp3rdepPMb/HfDp+f61Sdjb83icol5ept6jlfKCqBLMikPjSgms02qnpHIq
|
||||
HVxL6CJbpXAZfO6O8j4S/UTm6mqrvyZ8at4FcJ3yS5goY+4TH79ItG+P8r3lM+S6
|
||||
XJQGXAECgYEA7B0afEsUs2RYhkcd7g9yencopeu7GwU6I6kafxGTUVUiSMFC75ht
|
||||
HGQ4UF+8J0u7OksAz4ME3lGTstkCL6/ddRpJQbtinM79lGt+JAfjena/MwUovi9g
|
||||
SQysYOi7yi30hx4zThRMA/IvFsWuaAwFqo4Ar2MHrU3Khq7TYUnsO+ECgYEA5c62
|
||||
qbZJethPN0jT8dh90bAAbqZ6IkfFI6gaJMbLjF1zPDibd2YoLiy5kHmBgsvdbVKc
|
||||
k6YJqGfG1oCIUeFx+Gl96721931uPbylW6M4lgVJIwFBVF0MutZDK0OtR2I+G/ko
|
||||
hvDOCTbh1QT2eQb4UeT3qjM9k1ix51Dp1GvpYv0CgYAqlLkRD01FaORaGvs30otX
|
||||
sKOhAJk2r0Oj6LxBjD7gHRVYv5m9seSDiUNqo0lAYPT790jHI56+JUIYr/An/3RV
|
||||
yQ7LDusi0mWC3bva7Z1FmaKzpcuKOOsJYYK421/6fz0pHPYtr5Vh5Mw/NBlW5Ewl
|
||||
TQSsnJRm2a+biG3Qjs9OoQKBgQCeHdCIjKeaImK+wxkw+af4MoTZnSnDlGYL1onG
|
||||
bBF5DoNPGBO/30YeHx++TBvUBrjfk0uwOznB6UViKSWiUN+977d4EBu3oVHMoJOV
|
||||
rYQtlI1xzFdK2Ir9spacmgALcYkSbih4UA8zP9O6YaPEOgt5LXVKYd8oFoqxgXah
|
||||
dW4rcQKBgQDLwgs7NKBF/46l+WiDlyzcmeHQY2B+mB1n4atsbcOuDnKgDoQI5wqU
|
||||
+ZxWj4r7gnJ4EGA2n031m0AMGs1vQ+EnLtLMzQadv4Xhli6Mx0p7uFGS62/rWEco
|
||||
Osw897LzGhMyJu6u+CP7yYwkmNSfq9QBW+inqoYPwgBw1GMMxoM5HQ==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
6
backend/config.yaml
Normal file
6
backend/config.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
privatekey: ./certificate/private.pem
|
||||
dbuser: absensiUser
|
||||
dbpass: absensi102938
|
||||
dbhost: devone.aplikasi.web.id
|
||||
dbport: 3306
|
||||
dbname: absensi
|
||||
48
backend/go.mod
Normal file
48
backend/go.mod
Normal file
@@ -0,0 +1,48 @@
|
||||
module com.sismedika.com.absensi
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require (
|
||||
github.com/99designs/gqlgen v0.17.42
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/go-chi/chi v1.5.5
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/rs/cors v1.10.1
|
||||
github.com/spf13/viper v1.18.2
|
||||
github.com/vektah/gqlparser/v2 v2.5.10
|
||||
golang.org/x/crypto v0.18.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/agnivade/levenshtein v1.1.1 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.1 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sosodev/duration v1.2.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/urfave/cli/v2 v2.25.5 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.13.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
123
backend/go.sum
Normal file
123
backend/go.sum
Normal file
@@ -0,0 +1,123 @@
|
||||
github.com/99designs/gqlgen v0.17.42 h1:BVWDOb2VVHQC5k3m6oa0XhDnxltLLrU4so7x/u39Zu4=
|
||||
github.com/99designs/gqlgen v0.17.42/go.mod h1:GQ6SyMhwFbgHR0a8r2Wn8fYgEwPxxmndLFPhU63+cJE=
|
||||
github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM=
|
||||
github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=
|
||||
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
|
||||
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
|
||||
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
|
||||
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
|
||||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
|
||||
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g=
|
||||
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
|
||||
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
|
||||
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
|
||||
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
|
||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||
github.com/sosodev/duration v1.2.0 h1:pqK/FLSjsAADWY74SyWDCjOcd5l7H8GSnnOGEB9A1Us=
|
||||
github.com/sosodev/duration v1.2.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
|
||||
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
|
||||
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
||||
github.com/vektah/gqlparser/v2 v2.5.10 h1:6zSM4azXC9u4Nxy5YmdmGu4uKamfwsdKTwp5zsEealU=
|
||||
github.com/vektah/gqlparser/v2 v2.5.10/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
||||
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
87
backend/gqlgen.yml
Normal file
87
backend/gqlgen.yml
Normal file
@@ -0,0 +1,87 @@
|
||||
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
|
||||
schema:
|
||||
- graph/graphqls/*.graphqls
|
||||
|
||||
# Where should the generated server code go?
|
||||
exec:
|
||||
filename: graph/generated/generated.go
|
||||
package: generated
|
||||
|
||||
# Uncomment to enable federation
|
||||
# federation:
|
||||
# filename: graph/federation.go
|
||||
# package: graph
|
||||
|
||||
# Where should any generated models go?
|
||||
model:
|
||||
filename: graph/model/models_gen.go
|
||||
package: model
|
||||
|
||||
# Where should the resolver implementations go?
|
||||
resolver:
|
||||
layout: follow-schema
|
||||
dir: graph/resolver
|
||||
package: resolver
|
||||
filename_template: "{name}.resolvers.go"
|
||||
# Optional: turn on to not generate template comments above resolvers
|
||||
# omit_template_comment: false
|
||||
|
||||
# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
|
||||
# struct_tag: json
|
||||
|
||||
# Optional: turn on to use []Thing instead of []*Thing
|
||||
# omit_slice_element_pointers: false
|
||||
|
||||
# Optional: turn on to omit Is<Name>() methods to interface and unions
|
||||
# omit_interface_checks : true
|
||||
|
||||
# Optional: turn on to skip generation of ComplexityRoot struct content and Complexity function
|
||||
# omit_complexity: false
|
||||
|
||||
# Optional: turn on to not generate any file notice comments in generated files
|
||||
# omit_gqlgen_file_notice: false
|
||||
|
||||
# Optional: turn on to exclude the gqlgen version in the generated file notice. No effect if `omit_gqlgen_file_notice` is true.
|
||||
# omit_gqlgen_version_in_file_notice: false
|
||||
|
||||
# Optional: turn off to make struct-type struct fields not use pointers
|
||||
# e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing }
|
||||
# struct_fields_always_pointers: true
|
||||
|
||||
# Optional: turn off to make resolvers return values instead of pointers for structs
|
||||
# resolvers_always_return_pointers: true
|
||||
|
||||
# Optional: turn on to return pointers instead of values in unmarshalInput
|
||||
# return_pointers_in_unmarshalinput: false
|
||||
|
||||
# Optional: wrap nullable input fields with Omittable
|
||||
# nullable_input_omittable: true
|
||||
|
||||
# Optional: set to speed up generation time by not performing a final validation pass.
|
||||
# skip_validation: true
|
||||
|
||||
# Optional: set to skip running `go mod tidy` when generating server code
|
||||
# skip_mod_tidy: true
|
||||
|
||||
# gqlgen will search for any type names in the schema in these go packages
|
||||
# if they match it will use them, otherwise it will generate them.
|
||||
autobind:
|
||||
# - "com.sismedika.com.absensi/graph/model"
|
||||
|
||||
# This section declares type mapping between the GraphQL and go type systems
|
||||
#
|
||||
# The first line in each type will be used as defaults for resolver arguments and
|
||||
# modelgen, the others will be allowed when binding to fields. Configure them to
|
||||
# your liking
|
||||
models:
|
||||
ID:
|
||||
model:
|
||||
- github.com/99designs/gqlgen/graphql.ID
|
||||
- github.com/99designs/gqlgen/graphql.Int
|
||||
- github.com/99designs/gqlgen/graphql.Int64
|
||||
- github.com/99designs/gqlgen/graphql.Int32
|
||||
Int:
|
||||
model:
|
||||
- github.com/99designs/gqlgen/graphql.Int
|
||||
- github.com/99designs/gqlgen/graphql.Int64
|
||||
- github.com/99designs/gqlgen/graphql.Int32
|
||||
5446
backend/graph/generated/generated.go
Normal file
5446
backend/graph/generated/generated.go
Normal file
File diff suppressed because it is too large
Load Diff
28
backend/graph/graphqls/schema.graphqls
Normal file
28
backend/graph/graphqls/schema.graphqls
Normal file
@@ -0,0 +1,28 @@
|
||||
# GraphQL schema example
|
||||
#
|
||||
# https://gqlgen.com/getting-started/
|
||||
|
||||
type Todo {
|
||||
id: ID!
|
||||
text: String!
|
||||
done: Boolean!
|
||||
user: User!
|
||||
}
|
||||
|
||||
type User {
|
||||
id: ID!
|
||||
name: String!
|
||||
}
|
||||
|
||||
type Query {
|
||||
todos: [Todo!]!
|
||||
}
|
||||
|
||||
input NewTodo {
|
||||
text: String!
|
||||
userId: String!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createTodo(input: NewTodo!): Todo!
|
||||
}
|
||||
34
backend/graph/graphqls/staff.graphqls
Normal file
34
backend/graph/graphqls/staff.graphqls
Normal file
@@ -0,0 +1,34 @@
|
||||
# model staff
|
||||
type Staff {
|
||||
staff_id: ID!
|
||||
nip: String!
|
||||
name: String!
|
||||
email: String!
|
||||
phone_number: String
|
||||
is_active: String
|
||||
is_login: Boolean
|
||||
token: String
|
||||
id_google_sign_in: String!
|
||||
display_name_google_sign_in: String
|
||||
created_at: String
|
||||
last_updated_at: String
|
||||
}
|
||||
|
||||
# model token response ketika login
|
||||
type TokenResponse {
|
||||
token: String
|
||||
message: String
|
||||
}
|
||||
|
||||
# query search
|
||||
extend type Query {
|
||||
searchStaffByEmail(email: String!): Staff!
|
||||
staffGetByStaffId(staff_id: ID!): Staff!
|
||||
staffListBySearch(search:String, page:Int, maxPerPage: Int): [Staff!]!
|
||||
}
|
||||
|
||||
# mutation untuk perubahan data
|
||||
extend type Mutation {
|
||||
generateToken(email: String!, id_google_sign_in:String!): TokenResponse!
|
||||
loginAttendance(email:String!, id_google_sign_in:String!) : Staff!
|
||||
}
|
||||
46
backend/graph/model/models_gen.go
Normal file
46
backend/graph/model/models_gen.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
type Mutation struct {
|
||||
}
|
||||
|
||||
type NewTodo struct {
|
||||
Text string `json:"text"`
|
||||
UserID string `json:"userId"`
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
}
|
||||
|
||||
type Staff struct {
|
||||
StaffID string `json:"staff_id"`
|
||||
Nip string `json:"nip"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
PhoneNumber *string `json:"phone_number,omitempty"`
|
||||
IsActive *string `json:"is_active,omitempty"`
|
||||
IsLogin *bool `json:"is_login,omitempty"`
|
||||
Token *string `json:"token,omitempty"`
|
||||
IDGoogleSignIn string `json:"id_google_sign_in"`
|
||||
DisplayNameGoogleSignIn *string `json:"display_name_google_sign_in,omitempty"`
|
||||
CreatedAt *string `json:"created_at,omitempty"`
|
||||
LastUpdatedAt *string `json:"last_updated_at,omitempty"`
|
||||
}
|
||||
|
||||
type Todo struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Done bool `json:"done"`
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type TokenResponse struct {
|
||||
Token *string `json:"token,omitempty"`
|
||||
Message *string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
7
backend/graph/resolver/resolver.go
Normal file
7
backend/graph/resolver/resolver.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package resolver
|
||||
|
||||
// This file will not be regenerated automatically.
|
||||
//
|
||||
// It serves as dependency injection for your app, add any dependencies you require here.
|
||||
|
||||
type Resolver struct{}
|
||||
32
backend/graph/resolver/schema.resolvers.go
Normal file
32
backend/graph/resolver/schema.resolvers.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package resolver
|
||||
|
||||
// This file will be automatically regenerated based on the schema, any resolver implementations
|
||||
// will be copied through when generating and any unknown code will be moved to the end.
|
||||
// Code generated by github.com/99designs/gqlgen version v0.17.42
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"com.sismedika.com.absensi/graph/generated"
|
||||
"com.sismedika.com.absensi/graph/model"
|
||||
)
|
||||
|
||||
// CreateTodo is the resolver for the createTodo field.
|
||||
func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
|
||||
panic(fmt.Errorf("not implemented: CreateTodo - createTodo"))
|
||||
}
|
||||
|
||||
// Todos is the resolver for the todos field.
|
||||
func (r *queryResolver) Todos(ctx context.Context) ([]*model.Todo, error) {
|
||||
panic(fmt.Errorf("not implemented: Todos - todos"))
|
||||
}
|
||||
|
||||
// Mutation returns generated.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
// Query returns generated.QueryResolver implementation.
|
||||
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
||||
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
37
backend/graph/resolver/staff.resolvers.go
Normal file
37
backend/graph/resolver/staff.resolvers.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package resolver
|
||||
|
||||
// This file will be automatically regenerated based on the schema, any resolver implementations
|
||||
// will be copied through when generating and any unknown code will be moved to the end.
|
||||
// Code generated by github.com/99designs/gqlgen version v0.17.42
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"com.sismedika.com.absensi/graph/model"
|
||||
)
|
||||
|
||||
// GenerateToken is the resolver for the generateToken field.
|
||||
func (r *mutationResolver) GenerateToken(ctx context.Context, email string, idGoogleSignIn string) (*model.TokenResponse, error) {
|
||||
panic(fmt.Errorf("not implemented: GenerateToken - generateToken"))
|
||||
}
|
||||
|
||||
// LoginAttendance is the resolver for the loginAttendance field.
|
||||
func (r *mutationResolver) LoginAttendance(ctx context.Context, email string, idGoogleSignIn string) (*model.Staff, error) {
|
||||
panic(fmt.Errorf("not implemented: LoginAttendance - loginAttendance"))
|
||||
}
|
||||
|
||||
// SearchStaffByEmail is the resolver for the searchStaffByEmail field.
|
||||
func (r *queryResolver) SearchStaffByEmail(ctx context.Context, email string) (*model.Staff, error) {
|
||||
panic(fmt.Errorf("not implemented: SearchStaffByEmail - searchStaffByEmail"))
|
||||
}
|
||||
|
||||
// StaffGetByStaffID is the resolver for the staffGetByStaffId field.
|
||||
func (r *queryResolver) StaffGetByStaffID(ctx context.Context, staffID string) (*model.Staff, error) {
|
||||
panic(fmt.Errorf("not implemented: StaffGetByStaffID - staffGetByStaffId"))
|
||||
}
|
||||
|
||||
// StaffListBySearch is the resolver for the staffListBySearch field.
|
||||
func (r *queryResolver) StaffListBySearch(ctx context.Context, search *string, page *int, maxPerPage *int) ([]*model.Staff, error) {
|
||||
panic(fmt.Errorf("not implemented: StaffListBySearch - staffListBySearch"))
|
||||
}
|
||||
47
backend/pkg/config/config.go
Normal file
47
backend/pkg/config/config.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Reader interface {
|
||||
Get(key string) string
|
||||
}
|
||||
|
||||
type viperConfigReader struct {
|
||||
viper *viper.Viper
|
||||
}
|
||||
|
||||
var Data *viperConfigReader
|
||||
|
||||
func (v viperConfigReader) Get(key string) string {
|
||||
return v.viper.GetString(key)
|
||||
}
|
||||
|
||||
func (v viperConfigReader) GetInt(key string) int {
|
||||
return v.viper.GetInt(key)
|
||||
}
|
||||
|
||||
func Load() {
|
||||
v := viper.New()
|
||||
v.AddConfigPath(".")
|
||||
v.SetConfigName("config")
|
||||
v.SetConfigType("yaml")
|
||||
v.AutomaticEnv()
|
||||
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
Data = &viperConfigReader{
|
||||
viper: v,
|
||||
}
|
||||
v.WatchConfig()
|
||||
v.OnConfigChange(func(e fsnotify.Event) {
|
||||
log.Println("config file changed", e.Name)
|
||||
})
|
||||
return
|
||||
}
|
||||
98
backend/pkg/crypt/crypt.go
Normal file
98
backend/pkg/crypt/crypt.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package crypt
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"com.sismedika.com.absensi/pkg/config"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// openssl genrsa -out private.pem 1024
|
||||
// openssl rsa -in private.pem -outform PEM -pubout out public.pem
|
||||
func EncryptPassword(password string) (string, error) {
|
||||
pemData, err := ioutil.ReadFile(config.Data.Get("privatekey"))
|
||||
if err != nil {
|
||||
log.Printf("read key file: %s", err)
|
||||
return "", fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
block, _ := pem.Decode(pemData)
|
||||
if block == nil {
|
||||
log.Printf("bad key data: %s", "not PEM-encoded")
|
||||
return "", fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
if got, want := block.Type, "RSA PRIVATE KEY"; got != want {
|
||||
log.Printf("unknown key type %q, want %q", got, want)
|
||||
return "", fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
// Decode the RSA private key
|
||||
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
log.Printf("bad private key: %s", err)
|
||||
return "", fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
|
||||
passEncrypted, err := rsa.EncryptPKCS1v15(rand.Reader, &priv.PublicKey, []byte(password))
|
||||
if err != nil {
|
||||
log.Printf("decrypt: %s\n", err)
|
||||
return "", fmt.Errorf(("DECRYPTION_FAILED"))
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(passEncrypted), nil
|
||||
}
|
||||
|
||||
func DecryptPassword(passEncoded string) ([]byte, error) {
|
||||
/// decrypt password
|
||||
/// openssl genrsa -traditional -out private.pem 1024
|
||||
/// openssl rsa -in private.pem -outform PEM -pubout -out public.pem
|
||||
pemData, err := ioutil.ReadFile(config.Data.Get("privatekey"))
|
||||
if err != nil {
|
||||
log.Printf("read key file: %s", err)
|
||||
return nil, fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
block, _ := pem.Decode(pemData)
|
||||
if block == nil {
|
||||
log.Printf("bad key data: %s", "not PEM-encoded")
|
||||
return nil, fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
if got, want := block.Type, "RSA PRIVATE KEY"; got != want {
|
||||
log.Printf("unknown key type %q, want %q", got, want)
|
||||
return nil, fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
// Decode the RSA private key
|
||||
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
log.Printf("bad private key: %s", err)
|
||||
return nil, fmt.Errorf(("INTERNAL_SERVER_ERROR"))
|
||||
}
|
||||
|
||||
var passDecrypted []byte
|
||||
var passDecoded []byte
|
||||
passDecoded, err = base64.StdEncoding.DecodeString(passEncoded)
|
||||
if err != nil {
|
||||
log.Printf("base64 decode: %s\n", err)
|
||||
return nil, fmt.Errorf(("BASE64_DECODE_FAILED"))
|
||||
}
|
||||
|
||||
passDecrypted, err = rsa.DecryptPKCS1v15(rand.Reader, priv, []byte(passDecoded))
|
||||
if err != nil {
|
||||
log.Printf("decrypt: %s\n", err)
|
||||
return nil, fmt.Errorf(("DECRYPTION_FAILED"))
|
||||
}
|
||||
|
||||
return passDecrypted, nil
|
||||
}
|
||||
|
||||
func CheckPasswordHash(hash, password string) bool {
|
||||
start := time.Now()
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
log.Printf("CompareHashAndPassword execution took %s", time.Since(start))
|
||||
return err == nil
|
||||
}
|
||||
75
backend/pkg/database/database.go
Normal file
75
backend/pkg/database/database.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"com.sismedika.com.absensi/pkg/config"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
var Handle *sql.DB
|
||||
|
||||
func InitDB() {
|
||||
dsn := config.Data.Get("DBuser") + ":" + config.Data.Get("DBpass") + "@tcp(" + config.Data.Get("DBhost") + ":" + config.Data.Get("DBport") + ")/" + config.Data.Get("DBname")
|
||||
handle, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
if err = handle.Ping(); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
Handle = handle
|
||||
}
|
||||
|
||||
func LogSQL(query string, args ...interface{}) {
|
||||
var buffer bytes.Buffer
|
||||
nArgs := len(args)
|
||||
// Break the string by question marks, iterate over its parts and for each
|
||||
// question mark - append an argument and format the argument according to
|
||||
// it's type, taking into consideration NULL values and quoting strings.
|
||||
for i, part := range strings.Split(query, "?") {
|
||||
buffer.WriteString(part)
|
||||
if i < nArgs {
|
||||
switch a := args[i].(type) {
|
||||
case int:
|
||||
buffer.WriteString(fmt.Sprintf("%d", a))
|
||||
case int64:
|
||||
buffer.WriteString(fmt.Sprintf("%d", a))
|
||||
case bool:
|
||||
buffer.WriteString(fmt.Sprintf("%t", a))
|
||||
case sql.NullBool:
|
||||
if a.Valid {
|
||||
buffer.WriteString(fmt.Sprintf("%t", a.Bool))
|
||||
} else {
|
||||
buffer.WriteString("NULL")
|
||||
}
|
||||
case sql.NullInt64:
|
||||
if a.Valid {
|
||||
buffer.WriteString(fmt.Sprintf("%d", a.Int64))
|
||||
} else {
|
||||
buffer.WriteString("NULL")
|
||||
}
|
||||
case sql.NullString:
|
||||
if a.Valid {
|
||||
buffer.WriteString(fmt.Sprintf("%q", a.String))
|
||||
} else {
|
||||
buffer.WriteString("NULL")
|
||||
}
|
||||
case sql.NullFloat64:
|
||||
if a.Valid {
|
||||
buffer.WriteString(fmt.Sprintf("%f", a.Float64))
|
||||
} else {
|
||||
buffer.WriteString("NULL")
|
||||
}
|
||||
default:
|
||||
buffer.WriteString(fmt.Sprintf("%q", a))
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Print(buffer.String())
|
||||
}
|
||||
78
backend/pkg/jwt/jwt.go
Normal file
78
backend/pkg/jwt/jwt.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"com.sismedika.com.absensi/pkg/config"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
// var conf = config.Data
|
||||
|
||||
// GenerateToken generates a jwt token and assign a username to it's claims and return it
|
||||
func GenerateToken(user_id int, username string, staff_id int) (string, int64, error) {
|
||||
token := jwt.New(jwt.SigningMethodHS256)
|
||||
/* Create a map to store our claims */
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
/* Set token claims */
|
||||
expired := time.Now().Add(time.Minute * time.Duration(config.Data.GetInt("tokenExpiration"))).Unix()
|
||||
claims["user_id"] = user_id
|
||||
claims["user_name"] = username
|
||||
claims["staff_id"] = staff_id
|
||||
claims["exp"] = expired
|
||||
tokenString, err := token.SignedString([]byte(config.Data.Get("secretkey")))
|
||||
if err != nil {
|
||||
return "", 0, fmt.Errorf("GENERATE_TOKEN_FAILED")
|
||||
}
|
||||
return tokenString, expired, nil
|
||||
}
|
||||
|
||||
// ParseToken parses a jwt token and returns the username in it's claims
|
||||
func ParseToken(tokenStr string) (int, string, int, error) {
|
||||
claims := jwt.MapClaims{}
|
||||
|
||||
token, err := jwt.ParseWithClaims(tokenStr, claims, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(config.Data.Get("secretkey")), nil
|
||||
})
|
||||
if err != nil {
|
||||
v, _ := err.(*jwt.ValidationError)
|
||||
|
||||
if v.Errors == jwt.ValidationErrorExpired {
|
||||
log.Printf("parse token 1: %v\n", err)
|
||||
return 0, "", 0, fmt.Errorf("TOKEN_EXPIRED")
|
||||
}
|
||||
|
||||
log.Printf("parse token 2: %v\n", err)
|
||||
return 0, "", 0, fmt.Errorf("TOKEN_INVALID")
|
||||
}
|
||||
|
||||
if !token.Valid {
|
||||
log.Printf("token invalid: %v\n", err)
|
||||
return 0, "", 0, fmt.Errorf(("TOKEN_INVALID"))
|
||||
}
|
||||
|
||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||
if !ok {
|
||||
return 0, "", 0, fmt.Errorf(("TOKEN_INVALID"))
|
||||
}
|
||||
// type of user_id is float64: https://stackoverflow.com/questions/70705673/panic-interface-conversion-interface-is-float64-not-int64
|
||||
if claims["user_id"] == nil {
|
||||
return 0, "", 0, fmt.Errorf(("TOKEN_INVALID"))
|
||||
}
|
||||
if claims["user_name"] == nil {
|
||||
return 0, "", 0, fmt.Errorf(("TOKEN_INVALID"))
|
||||
}
|
||||
if claims["staff_id"] == nil {
|
||||
return 0, "", 0, fmt.Errorf(("TOKEN_INVALID"))
|
||||
}
|
||||
user_id := int(claims["user_id"].(float64))
|
||||
user_name := claims["user_name"].(string)
|
||||
staff_id := int(claims["practitioner_id"].(float64))
|
||||
return user_id, user_name, staff_id, nil
|
||||
} else {
|
||||
log.Printf("token claims: %v\n", err)
|
||||
return 0, "", 0, fmt.Errorf(("TOKEN_INVALID"))
|
||||
}
|
||||
}
|
||||
48
backend/server.go
Normal file
48
backend/server.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"com.sismedika.com.absensi/graph/generated"
|
||||
"com.sismedika.com.absensi/graph/resolver"
|
||||
"com.sismedika.com.absensi/pkg/config"
|
||||
"com.sismedika.com.absensi/pkg/database"
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
"github.com/99designs/gqlgen/graphql/playground"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/rs/cors"
|
||||
)
|
||||
|
||||
const defaultPort = "8080"
|
||||
|
||||
func main() {
|
||||
config.Load()
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = defaultPort
|
||||
}
|
||||
router := chi.NewRouter()
|
||||
// database
|
||||
database.InitDB()
|
||||
defer database.Handle.Close()
|
||||
|
||||
router.Use(
|
||||
// auth.Middleware(),
|
||||
// dataloader.Middleware,
|
||||
cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedHeaders: []string{"*"},
|
||||
AllowCredentials: true,
|
||||
Debug: false,
|
||||
}).Handler)
|
||||
|
||||
srv := handler.NewDefaultServer(
|
||||
generated.NewExecutableSchema(generated.Config{Resolvers: &resolver.Resolver{}}))
|
||||
|
||||
router.Handle("/", playground.Handler("GraphQL playground", "/query"))
|
||||
router.Handle("/query", srv)
|
||||
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
|
||||
log.Fatal(http.ListenAndServe(":"+port, router))
|
||||
}
|
||||
9
backend/tools/tools.go
Normal file
9
backend/tools/tools.go
Normal file
@@ -0,0 +1,9 @@
|
||||
//go:build tools
|
||||
// +build tools
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
_ "github.com/99designs/gqlgen"
|
||||
_ "github.com/99designs/gqlgen/graphql/introspection"
|
||||
)
|
||||
Reference in New Issue
Block a user